Cannot rm -rf node_modules && npm install


I recently have begun experiencing issues with the install phase of my build.

language: node_js

  - "6"

sudo: false

  - export PATH=/usr/local/phantomjs-2.0.0/bin:$PATH
  - npm config set spin false
  - "echo $NPM_TOKEN > ~/.npmrc"
  - npm install -g bower

  - rm -rf node_modules && npm install
  - rm -rf bower_components && bower install

  - npm test

  - node_modules/codecov/bin/codecov --token=$CODECOV_TOKEN -f coverage/

During the install phase, after removing node_modules, install exits with

rm -rf node_modules && npm install
/home/travis/.travis/functions: line 104: ./node_modules/.bin/npm: No such file or directory
The command "rm -rf node_modules && npm install" failed and exited with 127 during .

Project has admittedly outdated dependencies (Node 6 | NPM 2.15.5), but this only recently stopped working and upgrading is not feasible at this time. It also passes intermittently. Noticed in debug mode that even after installing npm globally, npm is still symlinked to binary in node_modules folder that is removed. Please advise.

Thanks much in advance,

I’m guessing that the shell still thinks that the command npm exists in ./node_modules/.bin/npm after rm -rf. If you think that npm should be available elsewhere on $PATH, you can try rehashing before invoking npm again.

rm -rf node_modules && rehash -r && npm install