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

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

    If you use yarn, the following command updates all packages to their latest version:

    yarn upgrade --latest

    From their docs:

    The upgrade --latest command upgrades packages the same as the upgrade command, but ignores the version range specified in package.json. Instead, the version specified by the latest tag will be used (potentially upgrading the packages across major versions).

    0 讨论(0)
  • 2020-11-22 08:24
    1. Use * as the version for the latest releases, including unstable
    2. Use latest as version definition for the latest stable version
    3. Modify the package.json with exactly the latest stable version number using LatestStablePackages

    Here is an example:

    "dependencies": {
            "express": "latest"  // using the latest STABLE version
        ,   "node-gyp": "latest"    
        ,   "jade": "latest"
        ,   "mongoose": "*" // using the newest version, may involve the unstable releases
        ,   "cookie-parser": "latest"
        ,   "express-session": "latest"
        ,   "body-parser": "latest"
        ,   "nodemailer":"latest"
        ,   "validator": "latest"
        ,   "bcrypt": "latest"
        ,   "formidable": "latest"
        ,   "path": "latest"
        ,   "fs-extra": "latest"
        ,   "moment": "latest"
        ,   "express-device": "latest"
    },
    
    0 讨论(0)
  • 2020-11-22 08:24

    The only caveat I have found with the best answer above is that it updates the modules to the latest version. This means it could update to an unstable alpha build.

    I would use that npm-check-updates utility. My group used this tool and it worked effectively by installing the stable updates.

    As Etienne stated above: install and run with this:

    $ npm install -g npm-check-updates
    $ npm-check-updates -u
    $ npm install 
    
    0 讨论(0)
  • 2020-11-22 08:24

    The above commands are unsafe because you might break your module when switching versions. Instead I recommend the following

    • Set actual current node modules version into package.json using npm shrinkwrap command.
    • Update each dependency to the latest version IF IT DOES NOT BREAK YOUR TESTS using https://github.com/bahmutov/next-update command line tool
    npm install -g next-update
    // from your package
    next-update
    
    0 讨论(0)
  • 2020-11-22 08:26

    If you happen to be using Visual Studio Code as your IDE, this is a fun little extension to make updating package.json a one click process.

    Version Lens

    0 讨论(0)
  • 2020-11-22 08:26
    • npm outdated
    • npm update

    Should get you the latest wanted versions compatible for your app. But not the latest versions.

    0 讨论(0)
提交回复
热议问题