MODULE_NOT_FOUND error after fresh socket-cli install
Closed this issue · 6 comments
After installing socket-cli globally on a machine running Xubuntu, I get the following error:
node:internal/modules/cjs/loader:1042
throw err;
^ng
Error: Cannot find module '/usr/share/nodejs/npm/node_modules/npmlog/lib/log.js'
Require stack:
- /usr/local/lib/node_modules/@socketsecurity/cli/lib/shadow/npm-injection.cjs
- internal/preload
at Module._resolveFilename (node:internal/modules/cjs/loader:1039:15)
at Module._load (node:internal/modules/cjs/loader:885:27)
at Module.require (node:internal/modules/cjs/loader:1105:19)
at require (node:internal/modules/cjs/helpers:103:18)
at Object.<anonymous> (/usr/local/lib/node_modules/@socketsecurity/cli/lib/shadow/npm-injection.cjs:128:16)
at Module._compile (node:internal/modules/cjs/loader:1218:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1272:10)
at Module.load (node:internal/modules/cjs/loader:1081:32)
at Module._load (node:internal/modules/cjs/loader:922:12)
at Module.require (node:internal/modules/cjs/loader:1105:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/usr/local/lib/node_modules/@socketsecurity/cli/lib/shadow/npm-injection.cjs',
'internal/preload'
]
}I’m not a linux expert yet. I couldn’t figure out how to install npmlog into the /usr/share directory.
What version of node and npm are you running?
$ node --version
$ npm --version- node: 18.13.0
- npm: 9.2.0
Managed to solve this by installing an additional node and npm via nvm. Now everything runs, served from directories of my normal user.
I wanted to try out the Socket CLI, but after following the safe-npm FAQ I'm receiving the same error listed in OP's initial comment. I tried Node.js v18 as well, but I still receive the same error.
@bmeck Is it expected that the Socket CLI doesn't work with Node.js version managers? OP mentioned using nvm on Xubuntu; I'm currently using fnm on macOS, but the error is exactly the same.
Here's my terminal output, with all commands being run from the ~/ user directory:
$ sw_vers
ProductName: macOS
ProductVersion: 14.5
BuildVersion: 23F79
$ fnm --version && which fnm
fnm 1.37.1
/opt/homebrew/bin/fnm
$ node -v && which node
v20.14.0
/Users/dustin/.local/state/fnm_multishells/73652_1718675711857/bin/node
$ npm -v && which npm
10.7.0
/Users/dustin/.local/state/fnm_multishells/73652_1718675711857/bin/npm
$ npm install --global @socketsecurity/cli
added 161 packages in 4s
64 packages are looking for funding
run `npm fund` for details
$ socket --version
0.9.3
$ socket npm install --save-dev typescript
node:internal/modules/cjs/loader:1148
throw err;
^
Error: Cannot find module '/Users/dustin/Library/Application Support/fnm/node-versions/v20.14.0/installation/lib/node_modules/npm/node_modules/npmlog/lib/log.js'
Require stack:
- /Users/dustin/Library/Application Support/fnm/node-versions/v20.14.0/installation/lib/node_modules/@socketsecurity/cli/lib/shadow/npm-injection.cjs
- internal/preload
at Module._resolveFilename (node:internal/modules/cjs/loader:1145:15)
at Module._load (node:internal/modules/cjs/loader:986:27)
at Module.require (node:internal/modules/cjs/loader:1233:19)
at require (node:internal/modules/helpers:179:18)
at Object.<anonymous> (/Users/dustin/Library/Application Support/fnm/node-versions/v20.14.0/installation/lib/node_modules/@socketsecurity/cli/lib/shadow/npm-injection.cjs:271:16)
at Module._compile (node:internal/modules/cjs/loader:1358:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1416:10)
at Module.load (node:internal/modules/cjs/loader:1208:32)
at Module._load (node:internal/modules/cjs/loader:1024:12)
at internalRequire (node:internal/modules/cjs/loader:176:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/Users/dustin/Library/Application Support/fnm/node-versions/v20.14.0/installation/lib/node_modules/@socketsecurity/cli/lib/shadow/npm-injection.cjs',
'internal/preload'
]
}
Node.js v20.14.0I am encountering a similar issue after installing socket. I tried using the following methods:
- yarn dlx socket optimize
- yarn add -D socket && socket optimize
- npx socket optimize
- npm install -g socket && socket optimize
All attempts lead to the same error.
$> node -v && which node
v23.1.0
/opt/homebrew/bin/node
$> npm -v && which npm
10.9.0
/opt/homebrew/bin/npm
$> npm install --global @socketsecurity/cli
(node:1914) ExperimentalWarning: CommonJS module /opt/homebrew/lib/node_modules/npm/node_modules/debug/src/node.js is loading ES Module /opt/homebrew/lib/node_modules/npm/node_modules/supports-color/index.js using require().
Support for loading ES Module in require() is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
npm warn deprecated @npmcli/move-file@1.1.2: This functionality has been moved to @npmcli/fs
npm warn deprecated inflight@1.0.6: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
npm warn deprecated npmlog@6.0.2: This package is no longer supported.
npm warn deprecated rimraf@3.0.2: Rimraf versions prior to v4 are no longer supported
npm warn deprecated rimraf@3.0.2: Rimraf versions prior to v4 are no longer supported
npm warn deprecated are-we-there-yet@3.0.1: This package is no longer supported.
npm warn deprecated glob@7.2.3: Glob versions prior to v9 are no longer supported
npm warn deprecated glob@7.2.3: Glob versions prior to v9 are no longer supported
npm warn deprecated boolean@3.2.0: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
npm warn deprecated gauge@4.0.4: This package is no longer supported.
added 751 packages in 4s
115 packages are looking for funding
run `npm fund` for details
$> socket optimize
node:internal/modules/cjs/loader:1249
throw err;
^
Error: Cannot find module 'registry-auth-token'
Require stack:
- /opt/homebrew/lib/node_modules/@socketsecurity/cli/dist/vendor.js
- /opt/homebrew/lib/node_modules/@socketsecurity/cli/dist/cli.js
at Function._resolveFilename (node:internal/modules/cjs/loader:1246:15)
at Function._load (node:internal/modules/cjs/loader:1072:27)
at TracingChannel.traceSync (node:diagnostics_channel:322:14)
at wrapModuleLoad (node:internal/modules/cjs/loader:216:24)
at Module.require (node:internal/modules/cjs/loader:1337:12)
at require (node:internal/modules/helpers:139:16)
at Object.<anonymous> (/opt/homebrew/lib/node_modules/@socketsecurity/cli/dist/vendor.js:13:20)
at Module._compile (node:internal/modules/cjs/loader:1572:14)
at Object..js (node:internal/modules/cjs/loader:1709:10)
at Module.load (node:internal/modules/cjs/loader:1315:32) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/opt/homebrew/lib/node_modules/@socketsecurity/cli/dist/vendor.js',
'/opt/homebrew/lib/node_modules/@socketsecurity/cli/dist/cli.js'
]
}
Node.js v23.1.0
@GauthierPLM Your issue, while similar, is different. It has been resolved in subsequent updates.