Installing packages from github npm registry - auth error 401

后端 未结 3 2042
囚心锁ツ
囚心锁ツ 2021-02-18 21:37

I have just published a private package on GitHub, trying to figure out how it should be working. now I\'m trying to install it in another project. I authenticated with np

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-18 21:57

    You need to generate a personal access token on Github and add it to your npm config in addition to setting the registry in the npm config:

    • In Github navigate to https://github.com/settings/tokens (Settings > Developer settings > Personal access tokens) and you should see something like this:

    • Click Generate new token
    • From the permissions select at least read:packages

    • Click Generate token and copy the token

    • Add the following to your local .npmrc:

      @{{OWNER}}:registry=https://npm.pkg.github.com
      //npm.pkg.github.com/:_authToken={{TOKEN}}
      

    Related: For Github Actions, be aware of the difference between the GITHUB_TOKEN and a personal access token. The Github Token's permissions are limited to the repository that contains your workflow. For anything else (including granular permissions beyond those allowed for the Github Token) you need a personal access token.

提交回复
热议问题