本文介绍了安装新软件包时 npm-force-resolutions 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 package.json 的脚本部分来强制解决:

I'm using the scripts section of the package.json to force resolutions:

"preinstall": "npx npm-force-resolutions"

在解决方案部分,我输入了具有指定版本的 graceful-fs:

in the resolutions section, I have entered graceful-fs with a specified version:

"resolutions": {
  "graceful-fs": "^4.2.4",
},

当我运行 npm i 时,一切都已正确安装,设置的版本会被考虑在内.但后来当我安装一个额外的模块时,例如npm i random-package,我设置的版本被丢弃了,我最终得到了 graceful-fs@1.2.3 和一些依赖项中的其他低版本.

When i run npm i everything is installed correctly, the set versions are taken in to account. But later on when I install an additional module, e.g. npm i random-package, my set versions are being thrown away and I endup with graceful-fs@1.2.3 and other low versions in some dependencies.

如果我清除 node_modules 文件夹并再次运行 npm i,一切都会再次正常.

If I clear the node_modules folder and run npm i again, everything is alright again.

我也尝试将分辨率设置得更具体,比如

I also tried setting the resolution more specific, like

"resolutions": {
  "glob/**/graceful-fs": "^4.2.4",
},

但这无济于事.

我也试过了:

  • 将模块添加为依赖项、devDependency 或 peerDependency
  • 使用收缩包装并在那里覆盖它

但没有运气.

我错过了什么?

推荐答案

对我来说自动化的最佳解决方案是如上所述修改预安装脚本:

The best solution for me to automate this was modifying preinstall script as above:

预安装":npm install --package-lock-only --ignore-scripts &&npx npm-force-resolutions",

这篇关于安装新软件包时 npm-force-resolutions 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-19 05:05