Nvm: Unable to update npm when on nvm

Created on 19 Oct 2017  Â·  8Comments  Â·  Source: nvm-sh/nvm

Hey!
So when I'm trying to update NPM on a system which uses NVM, things break:

[docker@devenv] /storage
$ node --version
v8.7.0
[docker@devenv] /storage
$ npm --version
5.4.2
[docker@devenv] /storage
$ npm install -g [email protected]
/home/docker/.nvm/versions/node/v8.7.0/bin/npm -> /home/docker/.nvm/versions/node/v8.7.0/lib/node_modules/npm/bin/npm-cli.js
/home/docker/.nvm/versions/node/v8.7.0/bin/npx -> /home/docker/.nvm/versions/node/v8.7.0/lib/node_modules/npm/bin/npx-cli.js
+ [email protected]
added 52 packages, removed 2 packages and updated 29 packages in 8.252s
[docker@devenv] /storage
$ npm --version
module.js:529
    throw err;
    ^

Error: Cannot find module 'semver'
    at Function.Module._resolveFilename (module.js:527:15)
    at Function.Module._load (module.js:476:23)
    at Module.require (module.js:568:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/home/docker/.nvm/versions/node/v8.7.0/lib/node_modules/npm/lib/utils/unsupported.js:2:14)
    at Module._compile (module.js:624:30)
    at Object.Module._extensions..js (module.js:635:10)
    at Module.load (module.js:545:32)
    at tryModuleLoad (module.js:508:12)
    at Function.Module._load (module.js:500:3)

This is on a system which isn't using NVM (just a straight install):

14:00:01 $ npm install -g [email protected]
/usr/local/bin/npm -> /usr/local/lib/node_modules/npm/bin/npm-cli.js
/usr/local/bin/npx -> /usr/local/lib/node_modules/npm/bin/npx-cli.js
+ [email protected]
added 151 packages, removed 37 packages and updated 72 packages in 13.084s

kstoney at macbook in [~/git/stono/devenv]  on git:master ✗  Removed the PeopleDa
14:00:23 $ npm --version
5.5.1

Any ideas?

Most helpful comment

This part seems problematic:

nvm is not compatible with the npm config "prefix" option: currently set to ""
Run `nvm use --delete-prefix v8.7.0 --silent` to unset it.
/bin/bash: npm: command not found

Are you sure your RUN /bin/bash command is properly sourcing nvm.sh prior to running its npm command? Can you RUN nvm debug in the same way, and provide its output?

(Note that "docker" isn't the same as "a generic system", and there's a Dockerfile in this repo that might be helpful)

All 8 comments

Okkkkkkkkkk this turned out to be a volume mount persisting some old nvm files.
Thanks anyway :-)

Actually nope, it's definitely an issue:

Step 52/61 : RUN /bin/bash -l -c "nvm install $DEVENV_NODEJS_VERSION && nvm use $DEVENV_NODEJS_VERSION && nvm cache clear"
 ---> Running in 5e1ca1cf9afc
Downloading and installing node v8.7.0...
Downloading https://nodejs.org/dist/v8.7.0/node-v8.7.0-linux-x64.tar.xz...
######################################################################## 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v8.7.0 (npm v5.4.2)
Creating default alias: default -> 8.7.0 (-> v8.7.0)
Now using node v8.7.0 (npm v5.4.2)
Cache cleared.
 ---> abc5afc5f8e6
Removing intermediate container 5e1ca1cf9afc
Step 53/61 : ARG DEVENV_NPM_VERSION
 ---> Running in 9e9df1a34fed
 ---> 0d7522639005
Removing intermediate container 9e9df1a34fed
Step 54/61 : RUN /bin/bash -l -c "npm install -g npm@$DEVENV_NPM_VERSION"
 ---> Running in f47187f2723a
/usr/local/nvm/versions/node/v8.7.0/bin/npm -> /usr/local/nvm/versions/node/v8.7.0/lib/node_modules/npm/bin/npm-cli.js
/usr/local/nvm/versions/node/v8.7.0/bin/npx -> /usr/local/nvm/versions/node/v8.7.0/lib/node_modules/npm/bin/npx-cli.js
+ [email protected]
added 52 packages, removed 2 packages and updated 29 packages in 7.951s
 ---> 98375c8f7995
Removing intermediate container f47187f2723a
Step 55/61 : RUN /bin/bash -l -c "npm install -g --depth=0 --no-summary --quiet grunt-cli npm-check-updates nsp depcheck jshint hawkeye-scanner thoughtdata-cli && npm cache clean --force"
 ---> Running in c424bb3e6bbc
module.js:529
    throw err;
    ^

Error: Cannot find module 'semver'
    at Function.Module._resolveFilename (module.js:527:15)
    at Function.Module._load (module.js:476:23)
    at Module.require (module.js:568:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/usr/local/nvm/versions/node/v8.7.0/lib/node_modules/npm/lib/utils/unsupported.js:2:14)
    at Module._compile (module.js:624:30)
    at Object.Module._extensions..js (module.js:635:10)
    at Module.load (module.js:545:32)
    at tryModuleLoad (module.js:508:12)
    at Function.Module._load (module.js:500:3)
nvm is not compatible with the npm config "prefix" option: currently set to ""
Run `nvm use --delete-prefix v8.7.0 --silent` to unset it.
/bin/bash: npm: command not found

This part seems problematic:

nvm is not compatible with the npm config "prefix" option: currently set to ""
Run `nvm use --delete-prefix v8.7.0 --silent` to unset it.
/bin/bash: npm: command not found

Are you sure your RUN /bin/bash command is properly sourcing nvm.sh prior to running its npm command? Can you RUN nvm debug in the same way, and provide its output?

(Note that "docker" isn't the same as "a generic system", and there's a Dockerfile in this repo that might be helpful)

I am having this same issue on Ubuntu for Windows 10. nvm install --lts installs node v6.11.5 and npm v3.10.10. If I try to update npm using either nvm install --lts --latest-npm or npm i -g npm@latest it fails and can no longer find npm.

@msroberts being on windows means you might have a different issue. Can you file a new one about it?

@ljharb I will check that I have the latest WSL and open an issue if the problem persists.

I ran into a similar issue on macOS - doing nvm uninstall [problematic version] && nvm install [my desired version] resolved this for me.

This seems resolved, so I'm going to close it - please file a new issue if not.

Was this page helpful?
0 / 5 - 0 ratings