73

Loooking at the npm install docs it looks possible to npm install from a github repo.

Is it also possible to install specifically from a pull request?

Is the solution just to install based on the last commit (last sha) of the pull request?

2 Answers 2

117

GitHub is maintaining a namespace for each PR in the original repo, so this works as well:

npm install <user>/<repo>#pull/<id>/head

NOTE: It doesn't seeem to be working with NPM v. 5. See the comment below. Works with npm 7.0.23 and possibly earlier versions. See the comment below.

for example:

npm i --save-dev json-schema-faker/json-schema-faker#pull/129/head

or with yarn:

yarn add <user>/<repo>#<id>/head

for example:

yarn add json-schema-faker/json-schema-faker#129/head

Note that in Yarn case there is no pull/ segment in the package identifier.

This may be helpful if you need to automate the installation or repo / branch from where PR is originating is removed. See also Modifying an inactive pull request locally at GitHub.

8
  • 2
    Yarn (or Github anymore?) doesn't seem to support pull in the tag. So for the example above it would be: json-schema-faker/json-schema-faker#129/head. There is also a 'merge' (rather than 'head') suffix for some PRs but I don't know what that means. Commented Mar 24, 2017 at 4:09
  • @DamonMaria It seems to be specific to yarn. Original npm client v. 4.1.2 still works with the command I've provided. I'll edit the answer for yarn. Thank you for pointing that out.
    – Tad Lispy
    Commented Mar 24, 2017 at 12:11
  • 1
    @shaune Yes, it's a known limitation of npm clients. They do not compile packages installed from git repositories. Take a look at my npm-git-install project for more details and possible solution.
    – Tad Lispy
    Commented May 20, 2017 at 9:59
  • 3
    I get the message that the 'pull/242/head' did not match any file(s) known to git
    – AlxVallejo
    Commented Jul 31, 2017 at 22:30
  • 1
    Hello, @AlxVallejo. Indeed it's not working in NPM v. 5. Unfortunately I can't investigate it right now. What I would do is to analyze the output of npm install --verbose <URL> for versions 4.x.x (where it's working) and 5.x.x. If you are using NVM it's easy to switch: nvm install 7 for NPM 4 and nvm install 8 for NPM 5. Good luck and please share your findings.
    – Tad Lispy
    Commented Aug 1, 2017 at 9:19
30

"How to install NodeJS package from GitHub directly?" mentions that you can specify a branch.

So if you know the repo and branch from which a PR comes from, you can do a:

npm install git+https://github.com/user/repo.git#branch 

Worth saying that you might need to escape the # to use a specific branch from the shell, i.e.:

npm install git+https://github.com/user/repo.git\#branch 

Note that repository you want to install must be a npm module, it must contain a package.json file or else you will get this error:

Error: ENOENT, open 'tmp.tgz-unpack/package.json'. 
1
  • If you get the following error, you might not have git installed correctly (or at all - like in an Alpine image) ``` npm ERR! code ENOENT npm ERR! syscall spawn git npm ERR! path git npm ERR! errno -2 npm ERR! enoent An unknown git error occurred ``` Commented Jul 27, 2022 at 18:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.