Skip to content

Conversation

@MaxBlack-dev
Copy link
Contributor

Description

This PR adds documentation explaining how npm install behaves with respect to package.json and package-lock.json, a common source of confusion for npm users.

Changes

  • Added a new section "How npm install uses package-lock.json" to the npm install documentation
  • Explained the two scenarios:
    • When package.json and package-lock.json are in sync: exact versions from lockfile are installed
    • When they conflict: package.json wins and package-lock.json is updated
  • Clarified that package.json is the source of truth for version ranges, while package-lock.json locks to specific versions
  • Noted the relationship to npm ci behavior

Context

The npm install documentation previously didn't explain how it handles the interaction between package.json and package-lock.json. Users were confused about when versions from the lockfile are used versus when they're updated. This PR incorporates the explanation from Kat Marchán that was referenced in the issue to provide clear guidance.

Closes #4866

@MaxBlack-dev MaxBlack-dev requested a review from a team as a code owner November 30, 2025 01:52

When you run `npm install` without arguments, npm verifies that `package.json` and `package-lock.json` are in sync:

* **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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to contradict itself, it does not install the exact versions in package-lock if the package-lock needs to be updated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching that! You're absolutely right - that was contradictory. I've updated the text to remove the confusing statement about updating package-lock.json from the "If they match" scenario, since that's already covered in the "If they don't match" case. The text now simply says npm "uses the versions specified in package-lock.json" without the contradictory language.

@MaxBlack-dev MaxBlack-dev force-pushed the docs/4866-package-lock-behavior branch from 11a4332 to 610564a Compare December 3, 2025 21:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[DOCS] Explain behavior of "npm install" w/r/t package versions in package-lock.json.

2 participants