我从另一个项目中复制了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"
}
}
有关纱线特定的解决方案,请参阅本堆栈溢出线程。
使用*作为最新版本的版本,包括不稳定版本使用最新版本作为最新稳定版本的版本定义使用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"
},
为npm v2更新+
npm 2+(节点0.12+):
npm outdated
npm update
git commit package-lock.json
古代npm(约2014年):
npm install -g npm-check-updates
npm-check-updates
npm shrinkwrap
git commit package-lock.json
一定要收缩你的部门,否则你可能会导致一个失败的项目。前几天我做了一个项目,但它无法运行,因为我的部门都过时了/更新了/一团糟。如果我收缩,npm就会安装我所需要的东西。
细节
对于走到这一步的好奇者,我推荐如下:
使用npm检查更新或npm过时来建议最新版本。
# `outdated` is part of newer npm versions (2+)
$ npm outdated
# If you agree, update.
$ npm update
# OR
# Install and use the `npm-check-updates` package.
$ npm install -g npm-check-updates
# Then check your project
$ npm-check-updates
# If you agree, update package.json.
$ npm-check-updates -u
###然后进行一次干净的安装(没有rm,我收到了一些依赖性警告)
$ rm -rf node_modules
$ npm install
最后,使用npm-shrinkwrap将精确版本保存到npm-shrykwrap.json
$ rm npm-shrinkwrap.json
$ npm shrinkwrap
现在,npm安装将使用npm-shrinkwrap.json中的精确版本
如果将npm-shrinkwrap.json签入git,则所有安装都将使用完全相同的版本。
这是一种从开发(所有更新,所有时间)过渡到生产(无人接触任何东西)的方法。
npm过时npm检查更新npm包络线
p.s.Yarn正在将您的包裹列表发送到Facebook。