如何从 GitHub 存储库中使用新标签更新 npm 依赖项?

huangapple go评论72阅读模式
英文:

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

huangapple
  • 本文由 发表于 2023年4月17日 03:23:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/76029909.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定