package-lock.json Explained

What package-lock.json does, with an example.

Published November 11, 2026

package-lock.json records the exact version of every installed package (and its dependencies) so installs are reproducible. Commit it to version control.

How it works

Where package.json holds ranges, the lockfile pins exact versions and integrity hashes. npm ci installs strictly from it.

Try it

npm install
(creates/updates package-lock.json)
git add package-lock.json

Practical examples

What it contains

{ "lockfileVersion": 3, "packages": { "node_modules/express": { "version": "4.19.2", "integrity": "sha512-..." } } }

Reproducible installs

npm ci

Update one package in the lock

npm update express

Resolve a merge conflict

git checkout --theirs package-lock.json
npm install

Common mistakes

  • Deleting it casually and getting different versions.
  • Editing it by hand.
  • Mixing lockfiles from different package managers.

Key takeaways

  • package-lock.json records the exact version of every installed package (and its dependencies) so installs are reproducible.
  • Run npm help <command> for every option.
  • Commit package-lock.json.

FAQ

Should I commit it?

Yes, for applications; libraries may also commit it for development.

Does this work with yarn or pnpm?

They have equivalents with similar commands.

More JavaScript articles