Skip to content

Commit 69517d6

Browse files
author
Max Black
committed
docs(npm-install): explain package-lock.json behavior during install
1 parent 4a32606 commit 69517d6

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

docs/lib/content/commands/npm-install.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ If the package has a package-lock, or an npm shrinkwrap file, or a yarn lock fil
1919

2020
See [package-lock.json](/configuring-npm/package-lock-json) and [`npm shrinkwrap`](/commands/npm-shrinkwrap).
2121

22+
#### How `npm install` uses `package-lock.json`
23+
24+
When you run `npm install` without arguments, npm verifies that `package.json` and `package-lock.json` are in sync:
25+
26+
* **If they match:** npm installs the exact versions specified in `package-lock.json`, ensuring reproducible builds across environments. This is similar to `npm ci` but also updates `package-lock.json` if needed.
27+
28+
* **If they don't match:** If you've modified `package.json` so that the version ranges no longer match what's in `package-lock.json`, npm treats it as if you ran `npm install <package>@<new-version>` for the changed packages. It will update `package-lock.json` with the new resolved versions that satisfy the updated `package.json` ranges.
29+
30+
In essence, `package-lock.json` locks your dependencies to specific versions, but `package.json` is the source of truth for acceptable version ranges. When they agree, the lockfile wins. When they conflict, `package.json` wins and the lockfile is updated.
31+
2232
A `package` is:
2333

2434
* a) a folder containing a program described by a [`package.json`](/configuring-npm/package-json) file

0 commit comments

Comments
 (0)