[BUG] npm update does not save new versions in package.json
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
Fix npm update to save new versions in package.json
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
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.
bashnpm install <package>@latest --save - 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.
bashnpm install -g npm-check-updates - 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.
bashncu -u - 4
Reinstall Dependencies
After updating package.json, run npm install to ensure that all dependencies are installed correctly based on the updated package.json.
bashnpm 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
Alex Chen
2450 rep