"npm ci" will fail if cached dependency includes npm

Travis is failing when running npm ci if a previous build had installed npm as a dependency, in this case semantic-release/npm, as ./node_modules/.bin is added to $PATH and so it’ll attempt to use ./node_modules/.bin/npm which gets deleted as the first part of npm ci.

My expected behavior would be to use the npm that was installed as part of nvm and not the one installed in the repo, especially if using npm ci.

Example Job: https://travis-ci.com/MasterOdin/node-sdk/jobs/215760973

Here’s a job with some more explicit echos and such to show what’s going on: https://travis-ci.com/MasterOdin/node-sdk/jobs/215823658, namely:

$ which npm

$ npm ci || true
npm WARN prepare removing existing node_modules/ before installation
npm ERR! Cannot find module './fetchers/version'
npm ERR! A complete log of this run can be found in:
npm ERR!     /home/travis/.npm/_logs/2019-07-13T19_58_08_209Z-debug.log

$ cat /home/travis/.npm/_logs/*
0 info it worked if it ends with ok
1 verbose cli [ '/home/travis/.nvm/versions/node/v6.17.1/bin/node',
1 verbose cli   '/home/travis/build/MasterOdin/node-sdk/node_modules/.bin/npm',
1 verbose cli   'ci' ]
2 info using npm@6.10.1
3 info using node@v6.17.1
1 Like

Are you using docker in travis?

Same error, @MasterOdin did you find a fix?

You could probably either add an install: npm install line (to not use npm ci), update the $PATH to point to the system npm and not the one under node_modules/bin, or disable the npm cache. For the repo in question, the maintainers chose the latter (disable the cache).

I tried this one, but ended up in an endless “npm install” loop eventually :smiley: Maybe because I am internally using this command in my pipeline…

Anyway, anyone tried disabling npm node module caching? Worked for me perfectly today. Will see tomorrow again :smile:

Here: https://docs.travis-ci.com/user/caching/#npm-cache

npm cache #

Please note that as of July 2019, npm is cached by default on Travis CI

To disable npm caching, use:

  npm: false