Command 'npm i -g npm@latest' fails

travis file is:

language: node_js
sudo: false
node_js:
  - '6'
  - '8'
  - '9'
  - '10'

before_install:
  - if [[ `node -v` = v6* ]]; then npm i -g npx; fi
  - npx --version

script:
  - node --version
  - npm --version
  - npx --version
  - npm run test-with-no-coverage-check
  # Update npm to check that audit analyzer is then (still) active
  - npm i -g npm@latest
  - node --version
  - npm --version
  - npx --version
  - npm test

link : https://travis-ci.org/inikulin/publish-please/jobs/443865361

1 Like

See the nvs item in Current known issues — Please read this before posting a new topic.

Hi @BanzaiMan

I think this issue is different. This issue is about npm i -g npm@latest is failing, I don’t see that in the common issues list.

Hey @jasongin

I was wondering if you could help with this.

The log line related to the failure is : https://travis-ci.org/inikulin/publish-please/jobs/443865359#L5685-L5688

It looks like npm is not able to replace the npm script when it is in use. I couldn’t reproduce this locally and find the root cause, but it happens every time on Travis.

Not using the script works:

node `npm prefix -g`/node_modules/npm/bin/npm-cli.js i -g npm@latest

Alternatively, setting a different global prefix also works:

if [[ "$TRAVIS_OS_NAME" == "windows" ]]; then export NPM_CONFIG_PREFIX=c:\\npm_prefix PATH="/c/npm_prefix:$PATH"; fi

At first I suspected nvs was run as Administrator, but confirmed this is not the case and the permissions of the nvs folder are correct.