强制安装npm包依赖不起作用

j9per5c4  于 2023-11-19  发布在  其他
关注(0)|答案(2)|浏览(176)

我的最终目标是安装grunt-html-validation,我的通用目标是知道如何强制安装npm包依赖项。我开始走这条路是因为当我运行npm audit时,我会遇到指向qs的高风险错误。当我运行npm install request@latestnpm install qs@latest时,我不会遇到任何错误。这样做之后,npm list qs不会反映预期的结果,即,如npm audit所建议的,用于将QS更新到最近的版本。

命令#1:

sudo npm install qs

字符串

获取:

npm WARN [email protected] requires a peer of grunt@~0.4.1 but none is installed. You must install peer dependencies yourself.
+ [email protected]
added 1 package from 1 contributor, updated 1 package and audited 623 packages in 4.014s
found 19 vulnerabilities (3 low, 10 moderate, 6 high)

命令#2:

sudo npm install request@latest

获取:

+ [email protected]
updated 1 package in 2.584s

命令#3:

npm list qs

获取:

[email protected]
|
[email protected]
|
[email protected]


我在故障排除中的观察/问题:-为什么[[email protected]](https://stackoverflow.com/cdn-cgi/l/email-protection)不更新?它位于依赖链的末尾。我删除了@my_project/node_modules/request/node_modules/qs,但没有帮助。然后我将@my_project/node_modules/request/package.json/dependencies/qs更新为~3.1.0,只是为了看看它是否会更新npm列表qs的结果。它没有,虽然@my_project/node_modules/request/node_modules/qs/package.json现在反映的是3.1.0版本。我也使用过几次npm cache clean-为什么Command#1没有更新依赖链中的[[email protected]](https://stackoverflow.com/cdn-cgi/l/email-protection)
我在npm install grunt-html-validation上也收到了这些警告:

npm WARN deprecated [email protected]: Use uuid module instead
npm WARN deprecated [email protected]: The major version is no longer supported. Please update to 4.x or newer
npm WARN [email protected] requires a peer of grunt@~0.4.1 but none is installed. You must install peer dependencies yourself.

gblwokeq

gblwokeq1#

已解决:所以很明显,问题是节点模块存储在我的项目目录中的节点模块中,它们有两层:grunt-html-validation => request => qs和request => qs
我不得不修改两个“request”文件夹的package.json文件,|做npm缓存清理,最后更新版本。

oalqel3c

oalqel3c2#

[[email protected]](https://stackoverflow.com/cdn-cgi/l/email-protection)依赖于request@~2.34.0,这意味着它将安装请求版本2.34.x,而不管你的根包依赖性如何。
最好的解决方案是让依赖项更新其依赖项,但对于像这样看似被遗弃的包,您也可以尝试在package.json中使用overrides,例如:

{
  "dependencies": {
    "grunt-html-validation": "^0.1.18"
  },
  "overrides": {
    "request": "2.88.0"
  }
}

字符串

相关问题