How to npm install updated commit hash from github

Say I have a dependency in my package.json, like:
"my_dependency": "git+https://<github repo>#<old commit hash>"

If I delete my package-lock and node_modules, and do an npm install, it works fine.
However, if I then push an update to my github repo that is my_dependency, I want to use the latest commit in my project. I go to github and fetch the commit hash <new commit hash>, then I edit my package.json file like so:
"my_dependency": "git+https://<github repo>#<new commit hash>"

Without deleting the current node_modules and package-lock, I run npm install, but when I look into my node modules or package-lock, the previous commit version remains.

Is this the incorrect approach? Apart from using the npm registry to manage my private packages, what can you recommend I do to overcome this problem?

I was not able to reproduce this problem with npm 6.11.3 on macOS. Editing the package.json to change the hash and reinstalling gave me the new version. Are you using an old version of npm?

In any case, a work-around might be to use npm to manage the dependencies. Instead of editing the package.json you could get npm to do the work:

npm i git+https://<github repo>#<new commit hash>

Hi @shadowspawn thank you for your quick response. I have tried this now with node: v10.16.0 npm: 6.11.3 however, I still find the same problem. Expanding on this, as it might be related to the problem, my project is actually comprised of a few multiple sub-projects (i.e. individual projects that have their own package.json files and are dependencies of the root level project’s package.json file), I guess it might be referred to as a “monorepo” however I don’t use lerna or yarn.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.