Reproducible installs with package-lock and npm ci
Quick answer
The npm lockfile records a resolved dependency tree. npm ci installs against that lock and refuses manifest-lock inconsistencies rather than silently repairing them.
Tooling examples
Example 1. Context: projects/npm-lab. Run in a fresh prepared fixture copy; see its README. Local check available; consult validation evidence for what was asserted.
npm ci --offline --ignore-scripts --no-audit --no-fundExpected observation: Install succeeds; package-lock.json remains byte-identical.
Example 2. Context: projects/npm-lab. Run in a fresh prepared fixture copy; see its README. This intentionally modifies only the disposable copy. Local check available; consult validation evidence for what was asserted.
# In a disposable copy only, add an unrecorded local dependency.npm pkg set "dependencies.@lesson/extra=file:tools/extra"npm ci --offline --ignore-scripts --no-audit --no-fundExpected observation: Nonzero exit status because manifest and lock do not agree.
How the tooling works
Commit package.json and package-lock.json together. Use npm install when intentionally changing dependencies and inspect the diff; use npm ci for clean builds. npm ci removes existing node_modules and does not rewrite manifests or locks. Reuse the install options that shaped the lock, and pin toolchain versions as needed: the same lock does not guarantee identical native binaries on different platforms. The lab uses local packages, no registry calls and --ignore-scripts to prevent lifecycle code during install.
Common mistakes
Do not delete a lockfile just to make a failing CI job pass. Investigate and deliberately regenerate if requirements changed.
Practice
In a disposable lab copy, add a new local dependency to the manifest without updating the lock. Observe npm ci failing, then restore the manifest.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Reproducible installs with package-lock and npm ci — Knowledge Check
Assess tooling contracts, diagnostic reasoning and transfer to a project.
Which command is appropriate when CI must enforce an existing npm lockfile?
What should be committed alongside package.json for repeatable npm application installs?
Why pin Node and npm versions separately from the lockfile?
In Reproducible installs with package-lock and npm ci, what is the expected observation for example 1 in its documented setup? npm ci --offline --ignore-scripts --no-audit --no-fund
In Reproducible installs with package-lock and npm ci, what is the expected observation for example 2 in its documented setup? # In a disposable copy only, add an unrecorded local dependency. npm pkg set "dependencies.@lesson/extra=file:tools/extra" npm ci --offline --ignore-scripts --no-audit --no-fund