npmnpm-installnpm-update

How to do `npm update` without modifying package.json?


I have couple of dependencies that they always need to be on the latest specific major version. So I added them to the package.json dependencies list like below:

{
...
  dependencies: {
    "A": "^12.0.0",
    "B": "^12.0.0",
    "C": "^12.0.0",
    ...

Lets say in package-lock.json, package B has version 12.2.2. A new version of package B arrives with version 12.3.0 and no updates for other packages exist.

When I do npm update the package.json file changes to below:

{
...
  dependencies: {
    "A": "^12.0.0",
    "B": "12.3.0",
    "C": "^12.0.0",
    ...

I don't want that to happen. I want package-lock.json and node_modules gets updated but package.json stays the same for package B.

I tried npm update --no-save, but that would only update node_modules and not the package-lock.json.

How can I achieve that?


Solution

  • The reason for this behavior was the .npmrc configuration file on the root of my project.

    I changed the .npmrc file to below:

    save-exact=false
    

    save-exact=false is the default config.

    Now with the fix, in my example, the package.json file should look like below after doing npm update:

    {
    ...
      dependencies: {
        "A": "^12.0.0",
        "B": "^12.3.0",
        "C": "^12.0.0",
        ...