Update Lock File Without Installing | Generated by AI
The --package-lock-only flag in npm install tells npm to only update the package-lock.json file without actually installing any packages in your node_modules folder.
This is useful when you want to:
-
Update the lock file after manually editing
package.json- you can regeneratepackage-lock.jsonto reflect your changes without downloading anything -
Resolve lock file conflicts - if you’re merging branches and have conflicts in
package-lock.json, you can runnpm install --package-lock-onlyto regenerate it based on your currentpackage.json -
Check what versions would be installed - you can see what the resolved dependency tree would look like without actually installing packages
-
Save time in CI/CD pipelines - if you only need to update the lock file for a commit, you don’t waste time downloading packages
For example:
npm install --package-lock-only
This contrasts with --dry-run (which shows what would be installed but doesn’t modify anything) and the normal npm install (which both updates the lock file and installs packages).