【问题标题】:How to use override in package.json to update child dependencies如何在 package.json 中使用 override 来更新子依赖项
【发布时间】:2022-07-13 17:01:23
【问题描述】:

我看到异步中的漏洞并希望将其更新为3.2.2 如果我这样做npm list async

,这就是依赖树
└─┬ webpack-dev-server@4.8.1
  └─┬ portfinder@1.0.28
    └── async@2.6.4

所以看着npmdocs我尝试在package.json中添加覆盖如下。

{
  "name": "some application",
  "scripts": {...},
  "dependencies": {...},
  "overrides": {
    "webpack-dev-server": {
      "portfinder": {
        "async": "3.2.2"
      }
    }
  },
  "devDependencies": {...}
}

但是当我执行npm install 时,它没有将异步版本更新到 3.2.2,并且仍然在 pacakge-lock.json 中显示旧版本。 我从 devDependencies 中删除了 webpack-dev-server 包,但在运行 npm install 后,npm list async 上的内容为空@

└── (empty)

知道我做错了什么吗?

【问题讨论】:

    标签: javascript node.js npm


    【解决方案1】:

    你把它倒过来了......你指定要覆盖哪个依赖项的版本(例如async),然后提供父母及其版本的版本或列表,所以它是这样的:

      "overrides": {
         "async": "3.2.2"
      },
    

    或者如果是具体的:

      "overrides": {
        "async": {
          "portfinder": "3.2.2"
        }
      },
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-07-03
      • 2014-10-16
      • 1970-01-01
      • 2023-02-23
      • 2019-02-15
      • 1970-01-01
      • 2012-01-31
      • 2021-09-29
      相关资源
      最近更新 更多