Skip to content
\n

This shows:

\n
    \n
  • \n

    Current: version installed in node_modules

    \n
  • \n
  • \n

    Wanted: latest version that matches the semver in package.json

    \n
  • \n
  • \n

    Latest: newest version available on the registry (even if outside your defined semver range)

    \n
  • \n
\n
\n

Use this to understand which updates are safe vs potentially breaking.

\n
\n

2. Audit for Vulnerabilities

\n
npm audit
\n
    \n
  • \n

    This checks for known vulnerabilities in installed packages and gives recommendations.

    \n
  • \n
  • \n

    To apply safe fixes (minor/patch):

    \n
  • \n
\n
npm audit fix
\n
    \n
  • For force-upgrades (may introduce breaking changes):
  • \n
\n
npm audit fix --force
\n

3. Upgrade All Packages Safely

\n

Install npm-check-updates (ncu):

\n
npm install -g npm-check-updates
\n

Check what can be upgraded:

\n
ncu
\n

Update your package.json with latest versions:

\n
ncu -u
\n

Then install them:

\n
npm install
\n
\n

✅ ncu updates your package.json directly, unlike npm update which only changes package-lock.json and node_modules.

\n
\n

4. Handle Peer Dependencies Carefully

\n

Run:

\n
npm ls
\n

Check for unmet peer dependencies or version mismatches.

\n
    \n
  • \n

    Use npm info to investigate compatible versions.

    \n
  • \n
  • \n

    Sometimes, upgrading one package (e.g., React) requires adjusting several peer packages.

    \n
  • \n
\n

5. Test Before Committing

\n

After updating:

\n
    \n
  • \n

    Run all unit/integration tests.

    \n
  • \n
  • \n

    Check app startup and build commands.

    \n
  • \n
  • \n

    Use git diff to inspect package-lock.json for unwanted changes.

    \n
  • \n
\n

Summary Table

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
TaskCommand
List outdated packagesnpm outdated
Run security auditnpm audit
Fix safe issuesnpm audit fix
Force fix (may break things)npm audit fix --force
View upgradeable packagesncu
Update package.json versionsncu -u
Install updated packagesnpm install
Check full dependency treenpm ls
","upvoteCount":1,"url":"https://github.com/orgs/community/discussions/160273#discussioncomment-13269713"}}}
Discussion options

You must be logged in to vote

🛠️ Step-by-Step Update Workflow:

1. Check for Outdated Packages

Run:

npm outdated

This shows:

  • Current: version installed in node_modules

  • Wanted: latest version that matches the semver in package.json

  • Latest: newest version available on the registry (even if outside your defined semver range)

Use this to understand which updates are safe vs potentially breaking.

2. Audit for Vulnerabilities

npm audit
  • This checks for known vulnerabilities in installed packages and gives recommendations.

  • To apply safe fixes (minor/patch):

npm audit fix
  • For force-upgrades (may introduce breaking changes):
npm audit fix --force

3. Upgrade All Packages Safely

Install npm-check-updates (ncu):

n…

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@ninguest
Comment options

@ninguest
Comment options

@9guest
Comment options

@ninguest
Comment options

Answer selected by ninguest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Programming Help Discussions around programming languages, open source and software development
2 participants