如何覆盖嵌套的 NPM 依赖版本? [英] How do I override nested NPM dependency versions?
问题描述
我想使用 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
明确要求grunt-lib-phantomjs
的版本"~0.2.0"
,这明确要求版本 <phantomjs
的代码>"~1.8.1".- 首先将
phantomjs
添加到我的包的依赖项中没有任何效果;两个版本都已安装,grunt-contrib-jasmine
仍使用旧版本(请参阅:使用 NPM 安装软件包时,您能否告诉它使用其依赖项之一的不同版本?).
grunt-contrib-jasmine
explicitly requires version"~0.2.0"
ofgrunt-lib-phantomjs
, which explicitly requires version"~1.8.1"
ofphantomjs
.- Adding
phantomjs
to my package's dependencies first has no effect; both versions are installed andgrunt-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屋!