Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
699 views
in Technique[技术] by (71.8m points)

node.js - Update local file dependency with npm

I have a project with a local file dependency in my package.json like this:

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

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?

I tried doing npm update but nothing happens.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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.

For more detail see the discussion about this issue on the official npm repository page: https://github.com/npm/npm/issues/7426


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...