Follow up on @John's answer.
To strictly adhere to package dependencies on package-lock.json
, the NPM install process on Travis CI now defaults to the new npm ci
(ci
stands for continuous integration, I think) instead of npm install
. This helps prevent installing packages that are not following proper semantic versioning.
To do this, npm ci
needs to first get rid of the dependency graph and all the cached compiled modules in node_modules
from previous builds so to restructure the dependency graph. It does so by removing node_modules
entirely before it begins its own installs. But that also means node_modules
can no longer be used as cache location on Travis. We must now use "$HOME/.npm"
to cache, and @John has explained the reason using "$HOME/.npm"
. Travis will throw an error at you complaining "/node_modules/.bin/npm cannot be found"
if you continue to use node_modules
as cache location, since node_modules
has been deleted when running npm ci
.
Now regarding which cache location to use...
$HOME/.npm
When you want to use the now default npm ci
, include these changes in your .travis.yml
# [optional] `npm ci` is now default on Travis
install:
- npm ci
# Keep the npm cache around to speed up installs
cache:
directories:
- "$HOME/.npm"
node_modules
If you wish to stick to the old npm install
# Specify `npm install`
install:
- npm install
# Continue to use the old cache location
cache:
directories:
- "node_modules"
Warning: your cache location depends on the install method of your choice, and cannot be intertwined with another. Otherwise you risk losing the benefits of caching, or worse, have a failed Travis build.
You can find more about npm ci
in the NPM docs.