\fBnpm-package-locks\fR\- An explanation of npm lockfiles
.SHDESCRIPTION
.P
Conceptually, the "input" to npm help install is a npm help 5 package\.json, while its
"output" is a fully\-formed \fBnode_modules\fP tree: a representation of the
dependencies you declared\. In an ideal world, npm would work like a pure
function: the same \fBpackage\.json\fP should produce the exact same \fBnode_modules\fP
tree, any time\. In some cases, this is indeed true\. But in many others, npm is
unable to do this\. There are multiple reasons for this:
.RS0
.IP\(bu2
different versions of npm (or other package managers) may have been used to install a package, each using slightly different installation algorithms\.
.IP\(bu2
a new version of a direct semver\-range package may have been published since the last time your packages were installed, and thus a newer version will be used\.
.IP\(bu2
A dependency of one of your dependencies may have published a new version, which will update even if you used pinned dependency specifiers (\fB1\.2\.3\fP instead of \fB^1\.2\.3\fP)
.IP\(bu2
The registry you installed from is no longer available, or allows mutation of versions (unlike the primary npm registry), and a different version of a package exists under the same version number now\.
.RE
.P
As an example, consider package A:
.P
.RS2
.nf
{
"name": "A",
"version": "0\.1\.0",
"dependencies": {
"B": "<0\.1\.0"
}
}
.fi
.RE
.P
package B:
.P
.RS2
.nf
{
"name": "B",
"version": "0\.0\.1",
"dependencies": {
"C": "<0\.1\.0"
}
}
.fi
.RE
.P
and package C:
.P
.RS2
.nf
{
"name": "C",
"version": "0\.0\.1"
}
.fi
.RE
.P
If these are the only versions of A, B, and C available in the
registry, then a normal \fBnpm install A\fP will install:
.P
.RS2
.nf
A@0\.1\.0
`\-\- B@0\.0\.1
`\-\- C@0\.0\.1
.fi
.RE
.P
However, if B@0\.0\.2 is published, then a fresh \fBnpm install A\fP will
install:
.P
.RS2
.nf
A@0\.1\.0
`\-\- B@0\.0\.2
`\-\- C@0\.0\.1
.fi
.RE
.P
assuming the new version did not modify B's dependencies\. Of course,
the new version of B could include a new version of C and any number
of new dependencies\. If such changes are undesirable, the author of A
could specify a dependency on B@0\.0\.1\. However, if A's author and B's
author are not the same person, there's no way for A's author to say
that he or she does not want to pull in newly published versions of C
when B hasn't changed at all\.
.P
To prevent this potential issue, npm uses npm help 5 package\-lock\.json or, if present,
npm help 5 shrinkwrap\.json\. These files are called package locks, or lockfiles\.
.P
Whenever you run \fBnpm install\fP, npm generates or updates your package lock,