Deterministic CI Builds & Cache Optimization
Use npm ci for a clean installation from an agreed manifest and lockfile. It refuses mismatches without rewriting the lock; complete build output still depends on the environment and scripts.
What is it?
npm ci stands for Clean Install. Unlike npm install, which attempts to resolve dependencies and can update package-lock.json, npm ci explicitly reads from the lockfile and fails if the package.json and lockfile are out of sync.
It also completely deletes the existing node_modules folder before installing, ensuring there are no orphaned packages from previous builds.
Why use it?
npm install can reconcile changed requirements and update a lockfile. npm ci makes disagreement an error, keeping automated installation separate from deliberate dependency updates.
An agreed lockfile controls resolved dependency choices. Platform-specific packages, runtime versions, configuration and install/build scripts can still make resulting files or complete builds differ.
How it works
In your GitHub Actions or GitLab CI pipelines, replace npm install with npm ci.
Cache npm download artifacts to reduce repeated fetching. Include the lockfile and relevant runtime/platform/configuration assumptions in the cache strategy; a cache hit does not guarantee that no network request will be needed.
Interactive Demo
Explore the concept in action using the interactive visualization below.
Check yourself
Pick an answer to lock it in, then read why. Getting one wrong is part of how it sticks.
Remember this
- Use npm ci when an automated installation must strictly follow an existing matching lockfile.
- npm ci reproduces locked dependency choices; complete build output can still depend on the environment and scripts.
npm cideletes thenode_modulesfolder before starting.- Cache npm download artifacts with a key reflecting the lockfile and relevant runtime/platform/configuration assumptions.
Done with this concept?
Mark it complete to track your progress. No login needed.