简体   繁体   English

使用npm更新本地文件依赖性

[英]Update local file dependency with npm

I have a project with a local file dependency in my package.json like this: 我在package.json有一个带有本地文件依赖项的项目,如下所示:

"dependencies": {
    "dep_1": "file:../../dep_1"
  }
}

When I do npm install it is installed into node_modules. 当我执行npm install它将安装到node_modules中。 But if I make changes to dep_1 how do I update the module version in node_modules? 但是,如果我对dep_1进行更改,如何更新node_modules中的模块版本?

I tried doing npm update but nothing happens. 我试过做npm update但没有任何反应。

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. 如果您使用的是相对较新版本的npm( 我使用的是2.14.2版 ),您可以在package.json中npm update dep_1版本号,并且npm update dep_1应该可以使用。 Otherwise how can npm know that something needs to be updated? 否则npm怎么知道需要更新的东西?

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. 您必须清理缓存以重置此行为。

However, you can forceably (and lazily) update local modules by simply running npm install again. 但是,您可以通过再次运行npm install来强制(并且懒惰地)更新本地模块。 eg 例如

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. 它应该很快,因为它在您的本地计算机上,您不必使用版本号。

For more detail see the discussion about this issue on the official npm repository page: https://github.com/npm/npm/issues/7426 有关更多详细信息,请参阅官方npm存储库页面上有关此问题的讨论: https//github.com/npm/npm/issues/7426

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM