Loading…
Loading documentation...
Understand what package-lock.json records, install from it with npm ci on build servers, and repair it when it disagrees with package.json.
Commands checked on 2026-10-13 with npm 11, Node.js 24.
You will know which of your two dependency files decides what gets installed, which install command to use on your own machine and which on a build server, and what to do when the two files disagree. Your builds will install the same packages every time, on every machine.
package.json and a package-lock.json. The app from Start a Next.js app with TypeScript, linting and a first test is the one used here.package.json holds ranges: what you are willing to accept.
"dependencies": {
"next": "16.4.0",
"react": "19.3.0",
"react-dom": "19.3.0"
}
package-lock.json holds the result: every package that was installed, the packages they brought with them, and for each one where it came from and a checksum of its content.
node -p 'require("./package-lock.json").lockfileVersion'
node -p 'Object.keys(require("./package-lock.json").packages).length'
On our project the answers are 3 and 507. Three packages were asked for; 507 were installed. One entry looks like this:
{
"version": "19.3.0",
"resolved": "https://registry.npmjs.org/react/-/react-19.3.0.tgz",
"integrity": "sha512-E8LUcbtBWt20bbl2YoHfx4Z..."
}
The integrity line is why a lockfile is also a safety measure: a package whose content changed after you locked it does not install.
npm ci
npm ci deletes node_modules, installs exactly what the lockfile lists, and never changes either file. On our project it took 10 seconds. Use it on build servers, in containers, and whenever you want to be sure your folder matches the repository.
npm install is for changing dependencies: it may update the lockfile to match package.json.
Add a dependency to package.json without installing it:
npm pkg set dependencies.is-odd="^3.0.1"
npm ci
npm ci refuses, and changes nothing:
npm error code EUSAGE
npm error `npm ci` can only install packages when your package.json and package-lock.json or npm-shrinkwrap.json are in sync. Please update your lock file with `npm install` before continuing.
npm error Missing: is-odd@3.0.1 from lock file
npm error Missing: is-number@6.0.0 from lock file
This refusal is the feature. A build server that silently resolved the new dependency would be running code nobody reviewed.
Bring the lockfile up to date without touching node_modules, then look at what changed before you commit it:
npm install --package-lock-only
git diff --stat package-lock.json
For this guide, undo the experiment instead:
git checkout package.json package-lock.json
npm ci
npm ci --omit=dev
du -sh node_modules
This leaves out everything under devDependencies: test tools, linters, type definitions. On our project it installed 22 packages where the full install has more than 400, and node_modules shrank from 535 MB to 342 MB. Use it for the final stage of a container image, after the build has run with the full install.
A project is reproducible when a clean copy installs and builds with nothing but the repository:
git status --porcelain package.json package-lock.json
npm ci
npm run build
The first command prints nothing: both files are committed. The other two succeed.
npm ci passes although you added a dependency by hand. It happened to us with zod: the package was already in the lockfile because another package depends on it, so the lockfile satisfied the new line. npm ci checks that the two files agree, not that you ran npm install. Add dependencies with npm install NAME, never by editing the file.package.json under engines.package-lock.json. Do not resolve it by hand. Resolve package.json, then run npm install --package-lock-only and let npm write the lockfile again.npm ci is slow on the build server. It downloads every package each time unless the cache survives between runs. npm config get cache prints the folder to keep; on our machine it is ~/.npm.package-lock.json for every application. Leaving it out means every install is a new experiment.npm ci wherever a human is not choosing versions: build servers, containers, deployment scripts.resolved address or a package you did not ask for is worth a question.Every Servers Are Up virtual machine and container includes an integrated HTML5 browser-based SSH, RDP, and VNC console in your dashboard, default-off inbound firewall rules with per-IP allow-lists, and full programmatic control via REST API v1 and Model Context Protocol (MCP). Explore our Virtual Datacenter Plans or reach out to Servers Are Up Support.