[BUG] npm update not updating package.json
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
Fix npm update not updating package.json
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
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.
bashrm -rf node_modules package-lock.json - 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.
bashcat package.json - 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.
bashnpm install --save - 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.
bashcat package.json - 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.
bashnpm 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
Alex Chen
2450 rep