npm Update Dependencies in package.json

A project’s dependency list may need updates as newer package releases become available. npm update selects package versions allowed by the ranges in package.json.

Learn how to check for outdated packages and choose whether an update should change their declared ranges.

TL;DR: Choose the update command by the change you want

Run npm update to install newer versions that fit the ranges in package.json. Use the save option when those ranges should move too.

  • Check npm outdated first to compare the installed version with the range in your manifest.
  • Review package.json and package-lock.json after the update.
  • Run the project tests before merging the lockfile changes.

What Is npm Update?

npm update selects package versions within your project’s declared semantic version ranges. package.json lists acceptable ranges for direct dependencies. package-lock.json records the resolved tree so installs can reproduce those selections.

A caret range such as ^4.17.15 permits compatible releases below the next major version. A tilde range such as ~4.17.15 permits patch updates within the same minor version. I check the operator first because my ^4.17.15 fixture accepted lodash 4.18.1.

A package.json manifest showing dependency ranges

The manifest may list packages under dependencies or devDependencies. Packages under dependencies are used by the application at runtime, while devDependencies support development work such as builds and tests.

A direct dependency is named in package.json. A transitive dependency comes through another package, and npm can update it only when the parent’s declared range allows. If a transitive version must move, review or update its parent instead of editing package-lock.json by hand.

How to Update npm Dependencies Step by Step

Inspect proposed versions before you update the project. Run these commands from the directory containing package.json, then test the application and review the changed files.

Step 1: Check which packages are outdated

Start with npm outdated. I ran it and saw Current 4.17.15 with Wanted 4.18.1. Latest was also 4.18.1.

npm outdated
Package  Current  Wanted  Latest  Location             Depended by
lodash   4.17.15  4.18.1  4.18.1  node_modules/lodash  outdated
npm outdated shows lodash current 4.17.15 and wanted and latest 4.18.1

Current is the installed version, and Wanted is the highest version inside your range. Latest is the registry tag. npm outdated returns exit code 1 when it finds a listed update, so read those columns before changing anything.

Step 2: Apply updates inside the declared ranges

In my test, npm update changed the installed lodash version while the manifest stayed at ^4.17.15.

npm update
changed 1 package, and audited 2 packages in 1s

found 0 vulnerabilities
npm update reports a completed dependency update

Check the manifest and installed tree after the update. The two commands I ran printed the range first and the installed version below it:

npm pkg get dependencies.lodash && npm ls lodash --depth=0
"^4.17.15"
[email protected] /home/ubuntu/.cache/journaldev-article-runs/codeforgeek-updating-dependencies-in-package-json-20261111T215356Z-a70a0d3501f2/no-save
└── [email protected]
npm update keeps the lodash range in package.json while installing lodash 4.18.1

Step 3: Change the declared range only when intended

Use the save option when you intend to change direct dependency ranges along with installed versions. Review the manifest diff because a changed range governs future installs too.

npm update --save
up to date, audited 2 packages in 593ms

found 0 vulnerabilities
npm update reports the dependency fixture is up to date

I checked the manifest afterward with npm pkg. Its output showed the new declared range:

npm pkg get dependencies.lodash
"^4.18.1"
npm pkg shows the updated lodash version range

Use npm-check-updates when a package version should move beyond the current range. I used it in a fixture to raise lodash from ^3.10.1 to ^4.18.1, then installed and checked the resolved version. The output marks a potentially breaking major update, so review the package notes before accepting it.

npx --yes npm-check-updates -u && npm install --ignore-scripts && npm ls lodash --depth=0
Upgrading /home/ubuntu/.cache/journaldev-article-runs/codeforgeek-updating-dependencies-in-package-json-20261111T215356Z-a70a0d3501f2/ncu-demo/package.json

Major   Potentially breaking API changes
 lodash  ^3.10.1  →  ^4.18.1

Run npm install to install new versions.

changed 1 package, and audited 2 packages in 933ms

found 0 vulnerabilities
[email protected] /home/ubuntu/.cache/journaldev-article-runs/codeforgeek-updating-dependencies-in-package-json-20261111T215356Z-a70a0d3501f2/ncu-demo
└── [email protected]
npm-check-updates changes lodash range and installs 4.18.1

A lockfile change can include transitive packages, which are required by your direct dependencies. npm update can resolve them when their constraints allow it. A transitive version change is temporary when the parent package keeps selecting that version.

Edge Cases: Major Versions, Lockfiles, and ERESOLVE

These cases call for different checks, so choose a response based on the file or error in front of you.

CaseWhat to checkNext move
Wanted is below LatestThe range blocks a newer release, often a major changeReview release notes, then widen the range only if the app supports it
ERESOLVE peer conflictThe error names the package and required peer rangeUpdate one side of the peer relationship, then retry
Lockfile mismatchManifest and lockfile describe different dependency statesRun npm install, review both files, and test

I caused a peer conflict by pairing React 17.0.2 with @testing-library/react 13.0.0. npm returned “npm error code ERESOLVE” and reported that the testing library requires react@”^18.0.0″. I fixed it by installing React from the compatible ^18 range.

npm install --ignore-scripts
npm error code ERESOLVE
npm error ERESOLVE unable to resolve dependency tree
npm error
npm error While resolving: [email protected]
npm error Found: [email protected]
npm error node_modules/react
npm error   react@"17.0.2" from the root project
npm error
npm error Could not resolve dependency:
npm error peer react@"^18.0.0" from @testing-library/[email protected]
npm error node_modules/@testing-library/react
npm error   @testing-library/react@"13.0.0" from the root project
npm error
npm error Fix the upstream dependency conflict, or retry this command with --force or --legacy-peer-deps to accept an incorrect (and potentially broken) dependency resolution.
npm error
npm error
npm error For a full report see:
npm error /home/ubuntu/.npm/_logs/2026-11-11T22_11_10_784Z-eresolve-report.txt
npm error A complete log of this run can be found in: /home/ubuntu/.npm/_logs/2026-11-11T22_11_10_784Z-debug-0.log
npm ERESOLVE peer dependency conflict between React 17 and testing library 13

I fixed it by installing React from the compatible ^18 range, then ran the install command again to verify the fixture.

npm install react@^18 --ignore-scripts
up to date, audited 88 packages in 814ms

47 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
npm install reports the React peer fixture is up to date

Run npm ls to check the installed packages.

npm ls react @testing-library/react --depth=0
[email protected] /home/ubuntu/.cache/journaldev-article-runs/codeforgeek-updating-dependencies-in-package-json-20261111T215356Z-a70a0d3501f2/peer-conflict-fresh
├── @testing-library/[email protected]
└── [email protected]
npm resolves the peer conflict with React 18.3.1 and testing library 13.0.0

For repeatable clean installs in automation, npm ci uses the committed lockfile and expects it to match package.json.

Conclusion

Start with npm outdated, decide whether the declared range should change, and test the resolved tree before merging. For the distinction between installation and update behavior, see npm install vs npm update and the Node.js overview. Confirm command details in the npm update documentation and npm outdated documentation.

FAQ

These answers clarify what npm updates and when to change a dependency range.

Does npm update change package.json?

By default, npm update changes installed versions and the lockfile while leaving direct dependency ranges in package.json unchanged. Use the save option when you intend to update those ranges.

Does npm update update transitive dependencies?

It can when the dependency tree’s constraints allow another resolution, but it cannot select a child version outside its parent’s declared range. Inspect npm ls output and update the parent package if the required child version remains unavailable.

How do I update a package beyond its current range?

Review the package’s compatibility notes, deliberately change its range in package.json, then install and test the updated tree. Avoid forcing a peer dependency conflict as a substitute for compatibility.

Vaibhav Raj
Vaibhav Raj

Vaibhav Raj writes about Node.js development and maintenance, including security, dependencies, modules, debugging, AWS integration, and running services. His work also covers database choices and Python tools.

Articles: 11