如何覆盖嵌套的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
仍使用旧版本(请参阅:
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收缩纸功能,以覆盖任何依赖性或子依赖性.
You can use npm shrinkwrap functionality, in order to override any dependency or sub-dependency.
我刚刚在我们的一个艰苦的项目中做到了这一点.从2.7.3开始,我们需要更新版本的connect.给我们带来麻烦所以我创建了一个名为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屋!