liveBook · Manning

Package-lock.json

As explained in Secrets of the JavaScript Ninja, Third Edition

A generated npm lockfile that records the resolved dependency tree and package versions for a project.

A generated npm lockfile records the exact dependency tree, complementing package.json, which can specify version ranges. When someone runs npm install, npm uses the lockfile to recreate that tree. section 3.2.3 section 3.4

Commit package-lock.json to version control, but leave node_modules out. This lets teammates reproduce dependencies without committing the downloaded packages; if a lockfile merge conflict occurs, running npm install can resolve it. section 3.2.3

"dependencies": {
  "express": "^5.1.0"
}

A package.json dependency can use a caret range, while the lockfile records the exact resolved versions. section 3.2.3

Whether to commit a lockfile for a package consumed by others is debated: it freezes versions during development, but does not control the dependency tree of downstream projects. section 3.2.3

How Secrets of the JavaScript Ninja, Third Edition covers it

How deep it goes
Explains exact dependency tracking, installation, version-control practice, and merge-conflict resolution without detailing the lockfile schema.
Examples
Uses an Express dependency with a caret range to contrast package.json with the lockfile's exact versions.
What it assumes
Assumes familiarity with npm dependencies and package.json, then distinguishes version ranges from exact resolved versions.
What you can do after
Operate/configure it by committing the lockfile, excluding node_modules, and running npm install to resolve merge conflicts.
How it connects
Distinguishes package.json version ranges from exact lockfile versions and connects both to npm install and node_modules.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Secrets of the JavaScript Ninja, Third Edition. The section links point to the parts of the book it draws on.