How to update each dependency in package.json to the latest version?

前端 未结 30 3498
清歌不尽
清歌不尽 2020-11-22 08:01

I copied package.json from another project and now want to bump all of the dependencies to their latest versions since this is a fresh project and I don\'t mind

30条回答
  •  情书的邮戳
    2020-11-22 08:18

    Solution without additional packages

    Change every dependency's version to *:

    "dependencies": {
        "react": "*",
        "react-google-maps": "*"
      }
    

    Then run npm update --save.

    Some of your packages were updated, but some not?

    "dependencies": {
        "react": "^15.0.1",
        "react-google-maps": "*"
      }
    

    This is the tricky part, it means your local version of "react" was lower than the newest one. In this case npm downloaded and updated "react" package. However your local version of "react-google-maps" is the same as the newest one.

    If you still want to "update" unchanged *, you have to delete these modules from node_modules folder.

    e.g. delete node_modules/react-google-maps.

    Finally run again npm update --save.

    "dependencies": {
        "react": "^15.0.1",
        "react-google-maps": "^4.10.1"
      }
    

    Do not forget to run npm update --save-dev if you want to update development dependencies.

提交回复
热议问题