19

I know how to make an NPM dependency from a GitHub release :

"dependencies": {
  "package-name": "user/repo#v1.0.0"
}

That's nice, but I want to install a specific binary from this release.

I tried

"dependencies": {
  "package-name": "https://github.com/user/repo/releases/download/v1.0.0/bin.tgz"
}

But I gives me the following error :

❯ npm install
npm ERR! fetch failed https://github.com/user/repo/releases/download/v1.0.0/bin.tgz
npm WARN retry will retry, error on last attempt: Error: fetch failed with status code 404

Binary release assets exist outside of GitHub and are using AWS S3.

The URL github.com/user/repo/releases/download/v1.0.0/bin.tgz is redirecting with a 302 status and a HTTP location header set to https://github-cloud.s3.amazonaws.com/releases/XXX/XXX...

If I try directly with the S3 URL I got a ENAMETOOLONG error (see NPM issue) :

> npm install https://github-cloud.s3.amazonaws.com/releases/XXX/XXX...
npm ERR! tarball.destroy is not a function
npm WARN retry will retry, error on last attempt: Error: ENAMETOOLONG: name too long, open '/var/folders/pn/......

Questions :

  • Why is NPM not following the redirect?
  • Why a 404?
  • Is there a way to link an NPM dependency to a GitHub release's binary tarball? How?

My context and needs :

  • I have a private GitHub repository
  • My package needs to be built before "deploying" (transpilation, etc.)
  • I want to "publish" a tarball of this build in my GitHub release and directly reference it to my NPM dependencies
  • I use a CI service to build, make the tarball and upload it next to the GitHub release
  • I would like to use GitHub release binary as a NPM repository

Related

Community
  • 1
  • 1
Yves M.
  • 29,855
  • 23
  • 108
  • 144

3 Answers3

2

I don't think npm provides a way to do this as per their documentation, they support using github's tarballs but not a specific binary attached to a release. https://docs.npmjs.com/cli/install The only way I see it would work is downloading the file and using the "tarball file" way described in the "npm install" docs.

I'm in the same boat and I think I'll end up using npm private repositories.

0

The 404 is because you are a private repo and didn't include the authentication in the url.

Public repo:

"agentframework": "https://codeload.github.com/agentframework/agentframework/tar.gz/beta"

Private repo:

  1. Create a private access token https://github.com/settings/tokens
  2. Create your own http proxy to download the assert from release. https://developer.github.com/v3/repos/releases/#get-a-single-release-asset
  3. Add the http proxy url to your package.json

package.json

{
  "name": "test",
  "version": "1.0.0",
  "dependencies": {
    "agentframework": "https://codeload.github.com/agentframework/agentframework/tar.gz/beta"
  }
}

BTW: You can use yarn install which I used in my projects

Ling
  • 1,033
  • 1
  • 9
  • 17
  • 2
    Can you explain in more detail how you set up the http proxy? – line72 Feb 13 '18 at 19:41
  • Same 404 happens with public repos – F Lekschas Mar 08 '19 at 15:21
  • @FLekschas, Thank you for pointing out this issue. I just check the code and found the reason is because GitHub changed their domain for downloading the releases. I have updated the answer. please try the new domain codeload.github.com – Ling Mar 11 '19 at 08:30
-1

Github Releases are based on Git Tags.

"...Versions are based on Git tags."

https://help.github.com/articles/creating-releases/

To specify a version with a Git URL, include an appropriate , such as a tag, at the end as a URL fragment. Example, for a tag named 0.3.1:

"dependencies": {
  "myprivatemodule": "git@github.com:...#0.3.1"
}

The snipped portion (...) should be filled in:

"myprivatemodule": "git@github.com:{owner}/{project}.git#0.3.1"

And, a different address format will be needed when SSH access isn't available:

"myprivatemodule": "git://github.com/{owner}/{project}.git#0.3.1"

kindly taken from: npm install from Git in a specific version

nmanh
  • 325
  • 2
  • 14
  • 4
    This works fine to have npm install from the codebase itself, but not to use binaries (e.g. a tarball containing build artifacts) uploaded to github releases – Laurent Aug 15 '18 at 21:47