Installing public npm packages from the GitHub package registry

Viewed 3531

1.I publish a public package in an organization repo.
The repo link : https://github.com/JX3BOX/jx3box-config/packages/141887

2.And I wanna install the package from another repo. I had set the dependencies in the package.json

"dependencies": {
    "@jx3box/jx3box-config": "^1.0.3",

and I created a file named .npmrc ,and set :

@jx3box:registry=https://npm.pkg.github.com

3.When I use github actions to build There is an error occur

Running build scripts... npm install && npm run build
npm ERR! code E401
npm ERR! Unable to authenticate, need: Basic realm="GitHub Package Registry"

It means maybe I need auth.But This is an public package.Is it should be auth too?

4.Now I had to prepend a line in the file .npmrc,just like

//npm.pkg.github.com/:_authToken=<mytoken>

But how can I set it in the actions . or because this is a public pkg,how can I don't need any auth?


Thanks a lot!! ^_^

2 Answers

This is probably solved but posting anyway because this question ranks high on Google.

From the GitHub Docs:

You need an access token to publish, install, and delete packages. You can use a personal access token to authenticate with your username directly to GitHub Packages or the GitHub API.[...]

You cannot install packages (even public ones) from the GitHub npm registry without being authenticated.

More details and multiple authentication methods here:

https://docs.github.com/en/packages/guides/configuring-npm-for-use-with-github-packages#authenticating-to-github-packages

The docs should be updated.

You need an access token to publish, install, and delete packages.

This should really be changed to;

You need an access token to publish, install, and delete both private and public packages.

Related