brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: npm ci gives a clean, reproducible install in CI

Tools
~/tips/tip-javascript-npm-ci-clean-install

npm ci

Installs exactly what the lockfile says, after wiping node_modules, so builds are the same every time.

npm install can quietly change your lockfile, and that is exactly what you do not want on a build server. npm ci is the stricter sibling.

npm ci

The npm documentation lists the differences with npm install. The project must already have a package-lock.json or npm-shrinkwrap.json. If the lockfile and package.json do not agree, npm ci exits with an error instead of updating the lockfile. It never writes to package.json or the lockfile, so installs are essentially frozen. And it can only install the entire project at once, so you cannot add a single package with it.

The part to be careful about: any existing node_modules folder is deleted before the install starts. That is fine in a CI job and in a fresh container. On your own laptop, it means a full reinstall, which takes a while and removes anything you installed there by hand.

In a pipeline, commit the lockfile and use npm ci as the install step, and keep npm install for the moment when you actually want to change dependencies on your own machine.

The caveat is that errors about a lockfile that is out of sync are the feature working, not a bug. Fix them by running npm install locally and committing the updated lockfile. The command also does not make a build reproducible when you leave out the lockfile or use a different npm version in CI than you have on your machine.

Further reading: npm documentation: npm ci

More Tools tips shuf -n 3 films.txt xmllint --format feed.xml pdftotext -layout invoice.pdf invoice.txt qrencode -t ANSIUTF8 'https://example.com/a/long/path?id=12345' where python All Tools tips (14) All topics

Link