我从另一个项目中复制了package.json,现在想将所有依赖项都升级到最新版本,因为这是一个新项目,如果出现问题,我不介意修复。

最简单的方法是什么?

我知道的最好的方法是运行npm info express版本,然后手动更新package.json中的每个依赖项。一定有更好的办法。

{
  "name": "myproject",
  "description": "my node project",
  "version": "1.0.0",
  "dependencies": {
    "express": "^3.0.3", // how do I get these bumped to latest?
    "mongodb": "^1.2.5",
    "underscore": "^1.4.2"
  }
}

有关纱线特定的解决方案,请参阅本堆栈溢出线程。


当前回答

如果你想通过一个漂亮的(终端)交互式报告界面使用一种温和的方法,我建议使用npm检查。

它不是一个锤子,给了你更多关于依赖关系更新的知识和控制。

为了让你尝一尝等待的滋味,这里有一张截图(从git页面中截取,用于npm检查):

其他回答

向上!

基于npm过时,updtr安装最新版本并为每个依赖项运行npm测试。如果测试成功,updtr会将新的版本号保存到package.json中。但是,如果测试失败,则updtr将回滚其更改。

https://github.com/peerigon/updtr

此功能已在npm v5中引入。使用npm install-g更新到npmnpm@latest和

更新package.json

delete/node_modules和package-lock.json(如果有)运行npm更新。这将基于semver将依赖关系package.json更新到最新版本。

更新到最新版本。您可以使用npm检查更新

使用*作为最新版本的版本,包括不稳定版本使用最新版本作为最新稳定版本的版本定义使用LatestStablePackages使用最新的稳定版本号修改package.json

下面是一个示例:

"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"
},

我通过查看https://github.com/tjunnone/npm-check-updates

$ npm install -g npm-check-updates
$ ncu
$ ncu -u # to update all the dependencies to latest
$ ncu -u "specific module name"  #in case you want to update specific dependencies to latest

您可以在shell中执行此操作,而不是为一次性用例安装另一个节点模块。。。

npm install $(npm outdated | tail -n +2 | awk '{print $1}' | sed -e 's/$/@latest/g' | tr '\n' ' ')