程序go 2013-04-18 02:39 采纳率: 100%
浏览 1632
已采纳

如何将 package.json 中的每个依赖更新为最新版本?

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 fixing something if it breaks.

What's the easiest way to do this?

The best way I know of now is to run npm info express version then update package.json manually for each one. There must be a better way.

{
  "name": "myproject",
  "description": "my node project",
  "version": "1.0.0",
  "engines": {
    "node": "0.8.4",
    "npm": "1.1.65"
  },
  "private": true,
  "dependencies": {
    "express": "~3.0.3", // how do I get these bumped to latest?
    "mongodb": "~1.2.5",
    "underscore": "~1.4.2",
    "rjs": "~2.9.0",
    "jade": "~0.27.2",
    "async": "~0.1.22"
  }
}

I am now a collaborator on npm-check-updates, which is a great solution to this problem.

转载于:https://stackoverflow.com/questions/16073603/how-do-i-update-each-dependency-in-package-json-to-the-latest-version

  • 写回答

30条回答 默认 最新

  • 撒拉嘿哟木头 2013-04-18 03:35
    关注

    Looks like npm-check-updates is the only way to make this happen now.

    npm i -g npm-check-updates
    ncu -u
    npm install
    

    On npm <3.11:

    Simply change every dependency's version to *, then run npm update --save. (Note: broken in recent (3.11) versions of npm).

    Before:

      "dependencies": {
        "express": "*",
        "mongodb": "*",
        "underscore": "*",
        "rjs": "*",
        "jade": "*",
        "async": "*"
      }
    

    After:

      "dependencies": {
        "express": "~3.2.0",
        "mongodb": "~1.2.14",
        "underscore": "~1.4.4",
        "rjs": "~2.10.0",
        "jade": "~0.29.0",
        "async": "~0.2.7"
      }
    

    Of course, this is the blunt hammer of updating dependencies. It's fine if—as you said—the project is empty and nothing can break.

    On the other hand, if you're working in a more mature project, you probably want to verify that there are no breaking changes in your dependencies before upgrading.

    To see which modules are outdated, just run npm outdated. It will list any installed dependencies that have newer versions available.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(29条)

报告相同问题?

悬赏问题

  • ¥15 docker环境配置
  • ¥20 绿盟安全扫描--检测到目标站点存在javascript框架库漏洞
  • ¥30 Android STD快速启动
  • ¥15 如何使用simulink建立一个永磁同步直线电机模型?
  • ¥30 天体光谱图的的绘制并得到星表
  • ¥15 PointNet++的onnx模型只能使用一次
  • ¥20 西南科技大学数字信号处理
  • ¥15 有两个非常“自以为是”烦人的问题急期待大家解决!
  • ¥30 STM32 INMP441无法读取数据
  • ¥15 R语言绘制密度图,一个密度曲线内fill不同颜色如何实现