问题描述
我的 package.json
中有一个具有本地文件依赖项的项目,如下所示:
I have a project with a local file dependency in my package.json
like this:
"dependencies": {
"dep_1": "file:../../dep_1"
}
}
当我执行 npm install
时,它被安装到 node_modules 中.但是如果我对 dep_1
进行了更改,我该如何更新 node_modules 中的模块版本?
When I do npm install
it is installed into node_modules. But if I make changes to dep_1
how do I update the module version in node_modules?
我尝试执行 npm update
但没有任何反应.
I tried doing npm update
but nothing happens.
推荐答案
如果您使用的是相对较新版本的 npm(我使用的是 2.14.2 版),您可以在包中增加版本号.json 和 npm update dep_1
应该可以工作.否则 npm 怎么会知道有什么东西需要更新?
If you are using a relatively new version of npm (I used version 2.14.2) you can bump the version number in package.json and npm update dep_1
should work. Otherwise how can npm know that something needs to be updated?
注意:这仅在版本高于之前安装的版本时才有效.您必须清理缓存才能重置此行为.
Note: This will only work if the version is higher than what has previously been installed. You will have to clean the cache to reset this behaviour.
但是,您只需再次运行 npm install
即可强制(且懒惰地)更新本地模块.例如
However, you can forceably (and lazily) update local modules by simply running npm install
again. e.g.
npm install dep_1
它应该很快,因为它在您的本地计算机上,您不必玩弄版本号.
It should be fast since its on your local computer and you don't have to play around with version numbers.
有关此问题的更多详细信息,请参阅官方 npm 存储库页面上有关此问题的讨论:https://github.com/npm/npm/issues/7426
For more detail see the discussion about this issue on the official npm repository page: https://github.com/npm/npm/issues/7426
这篇关于使用 npm 更新本地文件依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!