I cannot figure out how to update a package installed from a git repository.
Say I have a package at git+ssh://[email protected]:project/my-package.git
and it's already installed.
Now, if I:
- push into my-package master branch;
- run npm i or npm update;
then nothing gets updated.
I thought the version
field (from the dependent package.json
of my-package) might raise the problem so I removed it and re-installed the package from scratch. Unfortunately it didn't help, the package is still not being updated.
Any ideas?
I cannot figure out how to update a package installed from a git repository.
Say I have a package at git+ssh://[email protected]:project/my-package.git
and it's already installed.
Now, if I:
- push into my-package master branch;
- run npm i or npm update;
then nothing gets updated.
I thought the version
field (from the dependent package.json
of my-package) might raise the problem so I removed it and re-installed the package from scratch. Unfortunately it didn't help, the package is still not being updated.
Any ideas?
Share Improve this question asked Mar 20, 2020 at 11:57 OnkeltemOnkeltem 2,4682 gold badges27 silver badges36 bronze badges 6- Does this answer your question? npm git repository not updating versions – RobC Commented Mar 20, 2020 at 12:01
- @RobC Thanks, I saw that topic but it doesn't answer my question. The author uses mit hash which is not my case as I need my package to follow just the latest changes which is master branch I guess. – Onkeltem Commented Mar 20, 2020 at 12:45
-
Have you tried deleting the node_modules directory, then running
npm i
? – RobC Commented Mar 20, 2020 at 12:53 - Yes, Rob. It fetches the latest version as it should, but right after that it looses the ability to update it further: new mits of the master never get fetched again. – Onkeltem Commented Mar 20, 2020 at 12:57
- See issue #1727 - I think the only way currently is to re-install it again after each each mit to git. However, I'm sure this will be a feature very soon ! – RobC Commented Mar 20, 2020 at 13:17
1 Answer
Reset to default 10Ok, folks. Suprisingly, it doesn't seem possible to get it working out-of-the-box.
But there is a workaround. Thanks to @RobC for pointing me out to some old (yet never resolved) issue: https://github./npm/npm/issues/1727
The answer is in the last ment:
https://github./npm/npm/issues/1727#issuement-354124625
Basically, to update a git package you have to re-install it directly using: npm install package-name
.
Example. Say you already have your package installed and added to the dependencies like this:
{
"dependencies": {
"my-package": "git+ssh://[email protected]:prj/my-package.git"
}
}
Now, to get it updated whenever you issue npm i
all you have to do is to create a postinstall
script which would trigger npm i my-package
:
{
"dependencies": {
"my-package": "git+ssh://[email protected]:prj/my-package.git"
},
"scripts": {
"postinstall": "npm update && npm i my-package"
}
}
Now npm i
will be taking more time since it's gonna run install twice. But this is what we have now.