npm-force-resolutions在安装新软件包时不起作用 [英] npm-force-resolutions not working when installing a new package
问题描述
我正在使用 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我是随机包装
,我的固定版本被扔掉了,最终我得到了 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
- 使用收缩包装并将其覆盖在那里
但没有运气.
我想念什么?
推荐答案
嗨@NthDegree对我有用的唯一方法是,首先运行常规的npm install,然后将packages-lock.json文件添加到git中.完成此操作后,当您添加"preinstall":"npx npm-force-resolutions"时,它将始终将依赖项分辨率更新为提到的版本.
Hi @NthDegree the only way which worked for me was to first run the normal npm install and then add the packages-lock.json file to git. After doing that when you add "preinstall": "npx npm-force-resolutions", it always updates the dependency resolution to the version mentioned.
我不确定向git中添加packages-lock.json文件是好是坏,但是通过使用此方法,CI/CD管道也可以正常工作.
I am not sure if adding packages-lock.json file to git is good or bad but by using this method the CI/CD pipeline works as well.
这篇关于npm-force-resolutions在安装新软件包时不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!