I am trying to speed up the npm install during the build process phase. My package.json has the list of packages pretty much with locked revisions in it. I\'ve also configured t
Proposing two more modern approches:
1) npm ci
Use npm ci
, which is available from npm version 5.7.0
(although I recommend 5.7.1
and upwards because of the broken release) - this requires package-lock.json
to be present and it skips building your dependency tree off of your package.json
file, respecting the already resolved dependency URLs in your lock file.
A very quick
boost for your CI/CD envs (our build time was cut down to a quarter of the original!) and/or to make sure all your developers sit on the same versions of dependencies during development (without having to hard-code strict versions in your package.json
file).
Note however that npm ci
removes the node_modules/
directory before installing, so it won't benefit from any caching strategies.
2) npm i --prefer-offline
Use the --prefer-offline
flag with your regular npm install
/ npm i
. With this approach, you need to make sure you've cached your node_modules/
directory between builds (in a CI/CD environment). If it fails to find packages locally with the specific version, it falls back to the network safely.