'How to resolve "Cannot find module './common/helpers'" error when trying to install solcjs globally with npm?
I'm running into an issue while trying to install the Solidity compiler locally through npm. After running npm i -g solc and checking for installation by running any commands such as solcjs --help, I receive the following error:
internal/modules/cjs/loader.js:905
throw err;
^
Error: Cannot find module './common/helpers'
Require stack:
- /usr/local/lib/node_modules/solc/linker.js
- /usr/local/lib/node_modules/solc/translate.js
- /usr/local/lib/node_modules/solc/wrapper.js
- /usr/local/lib/node_modules/solc/index.js
- /usr/local/lib/node_modules/solc/solc.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
at Function.Module._load (internal/modules/cjs/loader.js:746:27)
at Module.require (internal/modules/cjs/loader.js:974:19)
at require (internal/modules/cjs/helpers.js:101:18)
at Object.<anonymous> (/usr/local/lib/node_modules/solc/linker.js:7:19)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)
at Module.require (internal/modules/cjs/loader.js:974:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/usr/local/lib/node_modules/solc/linker.js',
'/usr/local/lib/node_modules/solc/translate.js',
'/usr/local/lib/node_modules/solc/wrapper.js',
'/usr/local/lib/node_modules/solc/index.js',
'/usr/local/lib/node_modules/solc/solc.js'
]
}
I tried a variety of things including checking my NODE_PATH, manual installation from the solc-js GitHub, and trying to run the command with npx. However, none of these helped with the above error. For additional context, I am running on macOS Monterey. Would greatly appreciate any help regarding this.
Solution 1:[1]
According to this: https://github.com/ethereum/solc-js/issues/624, this is a bug introduced in 0.8.14.
It's going to be fixed in 0.8.15, in the meantime you can downgrade to 0.8.13 to avoid this.
Solution 2:[2]
I think it has to do with the version, I had to uninstall the current version
npm uninstall solcnpm install --save [email protected]
Solution 3:[3]
Worked for my 2 friends (MAC M1 & W10) and me
npm uninstall solc —globalnpm install —save [email protected] —global
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Antoine |
| Solution 2 | Tyler2P |
| Solution 3 | Tyler2P |
