1

I use the n version manager and when I change the Node version to 11.10 NPM stops working.

$ n latest
node/11.10.1

$ npm i  sinon
npm ERR! Cannot read property 'resolve' of undefined

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/myuser/.npm/_logs/2019-03-04T22_12_54_458Z-debug.log

$ npm --version
6.7.0

If I change back to the previous version of Node - or any earlier version really, it starts working again.

The full output from the debug log

0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'i', 'sinon' ]
2 info using npm@6.7.0
3 info using node@v11.10.1
4 verbose npm-session d32761bbecba8a12
5 silly install loadCurrentTree
6 silly install readLocalPackageData
7 silly fetchPackageMetaData error for sinon@^7.2.7 Cannot read property 'resolve' of undefined
8 timing stage:rollbackFailedOptional Completed in 0ms
9 timing stage:runTopLevelLifecycles Completed in 73ms
10 verbose stack TypeError: Cannot read property 'resolve' of undefined
10 verbose stack     at regFetch (/usr/local/lib/node_modules/npm/node_modules/npm-registry-fetch/index.js:76:23)
10 verbose stack     at fetchPackument (/usr/local/lib/node_modules/npm/node_modules/pacote/lib/fetchers/registry/packument.js:42:10)
10 verbose stack     at packument (/usr/local/lib/node_modules/npm/node_modules/pacote/lib/fetchers/registry/packument.js:20:10)
10 verbose stack     at getManifest (/usr/local/lib/node_modules/npm/node_modules/pacote/lib/fetchers/registry/manifest.js:22:10)
10 verbose stack     at manifest (/usr/local/lib/node_modules/npm/node_modules/pacote/lib/fetchers/registry/manifest.js:13:10)
10 verbose stack     at Object.manifest (/usr/local/lib/node_modules/npm/node_modules/pacote/lib/fetchers/registry/index.js:17:12)
10 verbose stack     at Object.Fetcher#manifest [as manifest] (/usr/local/lib/node_modules/npm/node_modules/genfun/lib/genfun.js:15:38)
10 verbose stack     at manifest (/usr/local/lib/node_modules/npm/node_modules/pacote/lib/fetch.js:23:18)
10 verbose stack     at pinflight (/usr/local/lib/node_modules/npm/node_modules/pacote/manifest.js:24:12)
10 verbose stack     at /usr/local/lib/node_modules/npm/node_modules/promise-inflight/inflight.js:29:24
10 verbose stack     at Promise._execute (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/debuggability.js:313:9)
10 verbose stack     at Promise._resolveFromExecutor (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/promise.js:483:18)
10 verbose stack     at new Promise (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/promise.js:79:10)
10 verbose stack     at _inflight (/usr/local/lib/node_modules/npm/node_modules/promise-inflight/inflight.js:28:25)
10 verbose stack     at /usr/local/lib/node_modules/npm/node_modules/promise-inflight/inflight.js:22:14
10 verbose stack     at tryCatcher (/usr/local/lib/node_modules/npm/node_modules/bluebird/js/release/util.js:16:23)
11 verbose cwd /tmp/foo
12 verbose Linux 4.15.0-34-generic
13 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "i" "sinon"
14 verbose node v11.10.1
15 verbose npm  v6.7.0
16 error Cannot read property 'resolve' of undefined
17 verbose exit [ 1, true ]
oligofren
  • 20,744
  • 16
  • 93
  • 180

2 Answers2

4

This seems to be a problem with n, or how it bundles NPM, for (only) version 11.10 of Node. Basically the global npm install is broken.

This is resolved if one uses n to revert to an earlier version of Node and NPM and downloads the same problematic release (6.7.0).

n 11.9
npm install -g npm@6.7
n 11.10

This seems to overwrite the existing cached, global download of NPM version 6.7.0 and fix the install. The fix persists to work, even after switching between Node versions, even though the npm command is reset to point to the default each time. This means that even if you do npm i npm@6.8 -g to do a global upgrade of npm it will be reset to 6.7 the next time you switch back and forth to Node 11.10.

oligofren
  • 20,744
  • 16
  • 93
  • 180
2

Are you running a version of n older than v2.1.12? n was updated in v2.1.12 to remove the previous npm node_modules folder during installation, to avoid problems when layout and content of the npm modules folder changes between versions.

If you have installed n using npm then, short version:

npm install -g n

Long version:

shadowspawn
  • 3,039
  • 22
  • 26