FG
🛠️ Developer ToolsMicrosoft

[BUG] npm update not updating package.json

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

Problem

npm update does not update and write to package.json node v12.14.1 npm v6.13.4 windows 10 pro 64-bit 1903 build 18362.592 Delete node_modules directory and package-lock.json, open cmd.exe and run the following: [code block] I'm expecting the contents of package.json to be updated. Here is my package.json: [code block]

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Fix npm update not updating package.json

Medium Risk

The issue arises because npm update does not modify package.json directly; it only updates the installed packages in node_modules and package-lock.json. If the package versions in package.json are not compatible with the latest versions available, npm update may not reflect changes in package.json as expected.

Awaiting Verification

Be the first to verify this fix

  1. 1

    Delete node_modules and package-lock.json

    Remove the existing node_modules directory and package-lock.json file to ensure a clean slate for package installation.

    bash
    rm -rf node_modules package-lock.json
  2. 2

    Check package.json for version ranges

    Ensure that the version ranges specified in package.json allow for updates. If they are locked to specific versions (e.g., '1.0.0'), consider changing them to ranges (e.g., '^1.0.0') to allow npm to update.

    bash
    cat package.json
  3. 3

    Run npm install with save flag

    Instead of using npm update, run npm install with the --save flag to explicitly update package.json with the latest compatible versions of the packages.

    bash
    npm install --save
  4. 4

    Verify package.json updates

    After running the npm install command, check the package.json file to confirm that the dependencies have been updated to their latest versions.

    bash
    cat package.json
  5. 5

    Reinstall packages if necessary

    If the packages are still not updating, consider manually specifying the latest versions in package.json and running npm install again.

    bash
    npm install <package-name>@latest --save

Validation

To confirm the fix worked, check that the package.json file reflects the updated versions of the packages after running the npm install command. Additionally, ensure that the node_modules directory contains the latest versions of the packages.

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

npmpackage-managernodejsenhancementrelease-7.xrelease-8.xpriority-1