英文:
How to update an npm dependency from a github repo with a new tag?
问题
I have a node.js project that uses some GitHub repos as dependencies. For example, the package.json
contains:
"dependencies": {
"some-lib": "github:some-org/some-lib#v1.0.0"
}
The #v1.0.0
is pointing to a specific tag (a release), and I want to switch to another release, e.g., v2.0.0
.
If I update the package.json
line to...
"dependencies": {
"some-lib": "github:some-org/some-lib#v2.0.0"
}
...and then run npm i
, lo and behold nothing happens (which I expected). So I delete package-lock.json
and do npm i
, and the library still does not get updated. I was under the impression that npm install
used the package-lock
file first, then package.json
second.
Finally, I do rm node_modules
, delete package-lock.json
, and do npm i
; the package is updated. What is a better way to do this? FWIW - I'm also maintaining the GitHub repo that I'm using, so can make changes there.
英文:
I have a node js project that uses some github repos as dependencies. For example, the package.json
contains:
"dependencies": {
"some-lib": "github:some-org/some-lib#v1.0.0"
}
The #v1.0.0
is pointing to a specific tag (a release), and I want to switch to another release, e.g., v2.0.0
.
If I update the package.json
line to...
"dependencies": {
"some-lib": "github:some-org/some-lib#v2.0.0"
}
...and then run npm i
, lo and behold nothing happens (which I expected). So I delete package-lock.json
and do npm i
and the library still does not get updated. I was under the impression that npm install
used the package-lock
file first, then package.json
second.
Finally I do rm node_modules
, delete package-lock.json
and do npm i
; the package is updated. What is a better way to do this? FWIW - I'm also maintaining the github repo that I'm using, so can make changes there.
答案1
得分: 1
根据npm package.json文档,您可以尝试将semver
添加到依赖项URL中。
这可能会为npm提供更多信息,以便在您在package.json
中更改依赖项版本号时更新模块。
"dependencies": {
"some-lib": "github:some-org/some-lib#semver:v2.0.0"
}
英文:
Based on the npm package.json docs you can try adding semver
to the dependency URL.
That might give npm more information so it updates the module when you change the dependency version number in your package.json
.
"dependencies": {
"some-lib": "github:some-org/some-lib#semver:v2.0.0"
}
答案2
得分: 0
可能需要执行rm -rf node_modules/your-module
以及删除包锁定,然后尝试npm install
来解决这个问题。
英文:
https://github.com/npm/npm/issues/1727
It may be that you need to rm -rf node_modules/your-module
as well as dropping the package lock, then try npm install
to resolve this
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论