我想使用“咕哝-贡献-茉莉花”NPM包。它有各种依赖关系。依赖关系图的一部分是这样的:

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

不幸的是,这个版本的phantomjs有一个错误,阻止它在Mac OS x上正确安装。这在最新版本中得到了修复。

我怎么能让grunt-lib-phantomjs使用一个新的版本的phantomjs?

一些附加上下文:

Grunt-contrib-jasmine明确要求版本为“~0.2.0”的grunt-lib-phantomjs,它明确要求版本为“~1.8.1”的phantomjs。 首先将phantomjs添加到包的依赖项中没有效果;两个版本都安装了,而unt-contrib-jasmine仍然使用旧版本(参见:当使用NPM安装一个包时,你可以告诉它使用一个依赖项的不同版本吗?)


当前回答

先运行这个

npm i -D @types/eslint@8.4.3

这将解决问题

其他回答

先运行这个

npm i -D @types/eslint@8.4.3

这将解决问题

我本来打算采用npm-force-resolution方法,但似乎只需要将依赖项包含在自己的包中就可以了。Json为我解决了这个问题。

我相信这在我的案例中是有效的,因为原始依赖项允许我想要更新的依赖项的补丁版本。因此,通过手动包含一个新版本,它仍然满足原始依赖项的依赖,并将使用我手动添加的依赖项。

例子

问题

我需要将plyr从3.6.8版本升级到3.6.9版本

Mine

package.json

{
  "dependencies": {
    "react-plyr": "^3.2.0"
  }
}

反应Plyr

package.json

{
  "dependencies": {
    "plyr": "^3.6.8"
  }
}

注意,对于plyr依赖,它以^开头,这意味着它可以接受任何小补丁。你可以在这里了解更多: https://docs.npmjs.com/about-semantic-versioning#using-semantic-versioning-to-specify-update-types-your-package-can-accept

更新我的

这将更新package.json中的plyr依赖。

package.json

{
  "dependencies": {
    "plyr": "^3.6.9",
    "react-plyr": "^3.2.0"
  }
}

从NPM v8.3开始,处理这个问题的正确方法是通过包的overrides部分。json文件。

If you need to make specific changes to dependencies of your dependencies, for example replacing the version of a dependency with a known security issue, replacing an existing dependency with a fork, or making sure that the same version of a package is used everywhere, then you may add an override. Overrides provide a way to replace a package in your dependency tree with another version, or another package entirely. These changes can be scoped as specific or as vague as desired. To make sure the package foo is always installed as version 1.0.0 no matter what version your dependencies rely on: { "overrides": { "foo": "1.0.0" } }

还有其他各种更细致的配置,允许您仅在某个包是特定包层次结构的依赖项时覆盖该包。欲了解更多详情,请访问https://docs.npmjs.com/cli/v8/configuring-npm/package-json#overrides

我有一个问题,其中一个嵌套依赖项有npm审计漏洞,但我仍然想维护父依赖项版本。npm的收缩膜解决方案不适合我,所以我所做的是覆盖嵌套的依赖版本:

删除package-lock.json中'requires'部分下的嵌套依赖项 在包的DevDependencies下添加更新的依赖项。Json,这样需要它的模块仍然能够访问它。 npm我

对于使用纱线的人。

我尝试使用npm收缩膜,直到我发现纱线cli忽略了我的npm收缩膜。json文件。

Yarn有https://yarnpkg.com/lang/en/docs/selective-version-resolutions/。整洁。

看看这个答案:https://stackoverflow.com/a/41082766/3051080