Cannot rm -rf node_modules && npm install

Hello,

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

language: node_js

node_js:
  - "6"

sudo: false

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

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

script:
  - npm test

after_success:
  - node_modules/codecov/bin/codecov --token=$CODECOV_TOKEN -f coverage/lcov.info

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,
bgroupe

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