如何覆盖嵌套的 NPM 依赖版本? [英] How do I override nested NPM dependency versions?

查看:66
本文介绍了如何覆盖嵌套的 NPM 依赖版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 grunt-contrib-jasmine NPM 包.它有各种依赖关系.部分依赖图如下所示:

I would like to use the grunt-contrib-jasmine NPM package. It has various dependencies. Part of the dependency graph looks like this:

─┬ grunt-contrib-jasmine@0.4.1
 │ ├─┬ grunt-lib-phantomjs@0.2.0
 │ │ ├─┬ phantomjs@1.8.2-2

不幸的是,此版本 phantomjs 中存在一个错误,使其无法在 Mac OS X 上正确安装.此问题已在最新版本中修复.

Unfortunately, there's a bug in this version phantomjs which prevents it from installing correctly on Mac OS X. This is fixed in the latest version.

如何让 grunt-lib-phantomjs 使用更新版本的 phantomjs?

How can I get grunt-lib-phantomjs to use a newer version of phantomjs?

一些额外的上下文:

  • grunt-contrib-jasmine explicitly requires version "~0.2.0" of grunt-lib-phantomjs, which explicitly requires version "~1.8.1" of phantomjs.
  • Adding phantomjs to my package's dependencies first has no effect; both versions are installed and grunt-contrib-jasmine still uses the older versions (see: When installing a package with NPM, can you tell it to use a different version of one of its dependencies?).

推荐答案

你可以使用 npm shrinkwrap 功能,以便覆盖任何依赖项或子依赖项.

You can use npm shrinkwrap functionality, in order to override any dependency or sub-dependency.

我刚刚在我们的 grunt 项目中完成了这项工作.我们需要更新版本的 connect,因为 2.7.3.给我们带来了麻烦.所以我创建了一个名为 npm-shrinkwrap.json 的文件:

I've just done this in a grunt project of ours. We needed a newer version of connect, since 2.7.3. was causing trouble for us. So I created a file named npm-shrinkwrap.json:

{
  "dependencies": {
    "grunt-contrib-connect": {
      "version": "0.3.0",
      "from": "grunt-contrib-connect@0.3.0",
      "dependencies": {
        "connect": {
          "version": "2.8.1",
          "from": "connect@~2.7.3"
        }
      }
    }
  }
}

npm 应该在为项目安装时自动选择它.

npm should automatically pick it up while doing the install for the project.

(参见:https://nodejs.org/en/blog/npm/managing-node-js-dependencies-with-shrinkwrap/)

这篇关于如何覆盖嵌套的 NPM 依赖版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆