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

前端 未结 30 3296
清歌不尽
清歌不尽 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:34

    Commands that I had to use to update package.json for NPM 3.10.10:

    npm install -g npm-check-updates
    ncu -a
    npm install
    

    Background:

    I was using the latest command from @josh3736 but my package.json was not updated. I then noticed the description text when running npm-check-updates -u:

    The following dependency is satisfied by its declared version range, but the installed version is behind. You can install the latest version without modifying your package file by using npm update. If you want to update the dependency in your package file anyway, run ncu -a.

    Reading the documentation for npm-check-updates you can see the difference:

    https://www.npmjs.com/package/npm-check-updates

    -u, --upgrade: overwrite package file

    -a, --upgradeAll: include even those dependencies whose latest version satisfies the declared semver dependency

    ncu is an alias for npm-check-updates as seen in the message when typing npm-check-updates -u:

    [INFO]: You can also use ncu as an alias
    

提交回复
热议问题