FG
🛠️ Developer ToolsMicrosoft

[BUG] npm update does not save new versions in package.json

Freshabout 19 hours ago
Mar 14, 20260 views
Confidence Score95%
95%

Problem

Current Behavior: When running `npm update`, packages are updated normally, package-lock.json is updated, but package.json is not. (`npm install [package]@[version]` does update package.json as expected.) Expected Behavior: The package.json file should be updated with the newly installed versions, as specified in the npm-update docs. Steps To Reproduce: - `npm update` - Check package.json Environment: OS: Mac OS Big Sur Node: 14.15.5 NPM: 7.5.4

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Fix npm update to save new versions in package.json

Medium Risk

The current behavior of npm update does not modify package.json because it is designed to update dependencies to their latest versions without altering the version constraints specified in package.json. This is by design, as npm update focuses on updating the package-lock.json to reflect the latest installed versions while maintaining the integrity of the version ranges defined in package.json.

Awaiting Verification

Be the first to verify this fix

  1. 1

    Manually Update package.json

    After running npm update, manually update the version numbers in package.json to match the versions in package-lock.json. This ensures that the package.json reflects the latest versions used in your project.

    bash
    npm install <package>@latest --save
  2. 2

    Use npm-check-updates

    Install npm-check-updates globally to help manage package.json updates. This tool can update the package.json file with the latest versions of dependencies.

    bash
    npm install -g npm-check-updates
  3. 3

    Run npm-check-updates

    Run the npm-check-updates command to update package.json with the latest versions of all dependencies. This will modify package.json directly.

    bash
    ncu -u
  4. 4

    Reinstall Dependencies

    After updating package.json, run npm install to ensure that all dependencies are installed correctly based on the updated package.json.

    bash
    npm install

Validation

Check the package.json file to confirm that the versions of the dependencies have been updated. Additionally, run npm list to verify that the installed versions match those specified in package.json.

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

npmpackage-managernodejspr:-needs-documentationrelease-7.xpriority-2