cmhteixeira
cmhteixeira

Reputation: 967

Cannot install npm package in Github registry

I have published a package to the GitHub npm registry. I can see the package when I login onto GitHub, as per the screenshots below.

ScreenShot 1 enter image description here

ScreenShot 2 enter image description here

Locally, a different package has the former as a dependency. Therefore I have on my package.json:

"dependencies": {
    "<@scope>/<package_name>": "1.2.0",
...

I also have, in-line with the documentation, a .npmrc file at the same directory as the package.json with the authToken. This authToken has all the permissions necessary (delete:packages, read:packages, repo, write:packages)

//npm.pkg.github.com/:_authToken=<my_auth_token>
registry=https://npm.pkg.github.com/OWNER

Lastly, I have on package.json the following two entries. Although I believe these are necessary to publish packages to the github registry, no to install them which is the current problem.

  "publishConfig": {
    "registry": "https://npm.pkg.github.com/"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/<OWNER>/<REPO>.git"
  }

So, the error that I am having when I try to install the package is:

npm ERR! code E404
npm ERR! 404 Not Found: <@scope>/<package_name>@1.2.0

When I tried to understand what was going on with some helpful logs: With npm install @<scope>/<package_name>@1.2.0 --loglevels verbose, I see:

....
npm http fetch GET 200 https://npm.pkg.github.com/OWNER/@<scope>%2f<package_name>
npm http fetch GET 404 https://npm.pkg.github.com/download/@<scope>/<package_name>/1.2.0/98e69e2adddec5c715a32c94352efac83ce586e4e6f3d06fef1fc1f82d238r34
...

The first http request is a success, which seems to indicate things are correctly wired up and authenticated. However, I have no idea why I am getting a 404 afterwards. The package is clearly there as we see on the image above.

Does anyone had a similar problem ?

Upvotes: 12

Views: 8136

Answers (4)

Anny Gutierrez
Anny Gutierrez

Reputation: 139

I had a similar problem where I was getting 404 and 403. I ended up changing my .npmrc to look like this:

@myusername:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=TOKEN

Now it works like a charm.

Upvotes: 0

cyrf
cyrf

Reputation: 5993

I had misread the checkboxes in my PAT. Make sure you've enabled read:packages.

My successful .npmrc file looks like this:

//npm.pkg.github.com/:_authToken=TOKEN_GOES_HERE

Upvotes: 0

user2483352
user2483352

Reputation: 113

I just ran into the same issue. Removing package-lock.json fixed it for me. I suspect the problem was that I previously installed the offending package from a tarball and that the old installation information was somehow cached inside the package-lock.json

Upvotes: 1

Romain Pr&#233;vost
Romain Pr&#233;vost

Reputation: 543

Well, my own .npmrc (in my home directory) is configured as this:

//registry.npmjs.org/:_authToken=<token>
//npm.pkg.github.com/:_authToken=<token>
@myorg1:registry=https://npm.pkg.github.com
@myorg2:registry=https://registry.npmjs.org

I've not added my org in the github registry URL as you did, and specified the registry to use for each scope.

Upvotes: 8

Related Questions