如何处理冲突的对等依赖关系?

use*_*695 32 npm

作为 devDependency 我已经安装了"@typescript-eslint/parser": "~4.31.2"

运行告诉我,如果我正确理解错误,则npm install需要一个包4.20.0和另一个包。4.28.3

如何处理这些 npm 包冲突?

npm ERR! While resolving: @nrwl/eslint-plugin-nx@12.9.0
npm ERR! Found: @typescript-eslint/parser@4.31.2
npm ERR! node_modules/@typescript-eslint/parser
npm ERR!   dev @typescript-eslint/parser@"~4.31.2" from the root project
npm ERR!   @typescript-eslint/parser@"^4.20.0" from eslint-config-next@11.1.2
npm ERR!   node_modules/eslint-config-next
npm ERR!     dev eslint-config-next@"11.1.2" from the root project
npm ERR!     eslint-config-next@"^11.1.0" from @nrwl/next@12.9.0
npm ERR!     node_modules/@nrwl/next
npm ERR!       dev @nrwl/next@"12.9.0" from the root project
npm ERR!   1 more (@typescript-eslint/eslint-plugin)
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer @typescript-eslint/parser@"~4.28.3" from @nrwl/eslint-plugin-nx@12.9.0
npm ERR! node_modules/@nrwl/eslint-plugin-nx
npm ERR!   dev @nrwl/eslint-plugin-nx@"12.9.0" from the root project
npm ERR! 
npm ERR! Conflicting peer dependency: @typescript-eslint/parser@4.28.5
npm ERR! node_modules/@typescript-eslint/parser
npm ERR!   peer @typescript-eslint/parser@"~4.28.3" from @nrwl/eslint-plugin-nx@12.9.0
npm ERR!   node_modules/@nrwl/eslint-plugin-nx
npm ERR!     dev @nrwl/eslint-plugin-nx@"12.9.0" from the root project
Run Code Online (Sandbox Code Playgroud)

Tro*_*ott 51

您使用的是npm7.x,它比npm6.x对对等依赖关系更严格。npm install最简单的解决方案是使用标志运行--legacy-peer-deps。理论上,这可能会导致与对等依赖项的一些不兼容问题。实际上,很多人还是这么做的。很多人都在运行npm6.x,这是默认行为,所以很多人可能在没有意识到的情况下就这样做了。

在你的情况下,@nrwl/eslint-plugin-nx@12.9.0说它需要@typescript-eslint/parser@4.28.x并且你正在安装@typescript-eslint/parser@4.31.2。因此,如果您不想使用npm6.x 或--legacy-peer-deps解决方案,另一种可能性是安装@typescript-eslint/parser@4.28.5而不是 4.31.2。

您可以做的另一件事是打开拉取请求以更新以在相关条目中@nrwl/eslint-plugin-nx使用而不是. 这将允许 4.x 实现对等依赖,而不是将其限制为 4.28.x。他们可能是故意如此严格地限制它,但也可能不是。(我去看了,但该存储库中打开了数百个问题,因此我没有花时间查看它们。)^peerDependencies~