1

I have a private repo inside my free github organization. When I try to publish a private package to Github Packages with Actions, I get the following error:

npm ERR! 401 Unauthorized - PUT https://npm.pkg.github.com/@organization%2ftailwind - Your request could not be authenticated by the GitHub Packages service. Please ensure your access token is valid and has the appropriate scopes configured.

my github action main.yml file looks like this:

name: Node.js Package

on: 
  push:
    branches:
      - main
      
jobs:
  publish-gpr:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v1
        with:
          node-version: 12
          registry-url: https://npm.pkg.github.com/
          scope: '@organization'
      - run: npm install
      - run: npm publish
        env:
          NODE_AUTH_TOKEN: $({secrets.GITHUB_TOKEN})

and my package.json looks like this:

{
  "name": "@organization/tailwind",
  "version": "1.0.0",
  "description": "My Package Description",
  "main": "index.js",
  "publishConfig": {
    "registry": "https://npm.pkg.github.com/@organization"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/organization/tailwind.git"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/organization/tailwind/issues"
  },
  "homepage": "https://github.com/organization/tailwind#readme"
}

What do I need to change to get this working? I also tried to use a personal access token with read/write packages permissions from my github account but this also doesn't work.

fmatt
  • 464
  • 1
  • 5
  • 15
Niklas
  • 1,638
  • 4
  • 19
  • 48
  • I would say that the token does not have enough permissions to perform the task as the error message says. You can create a new token and set the necessary permissions yourself. The procedure is described in the [documentation](https://docs.github.com/en/actions/reference/authentication-in-a-workflow#permissions-for-the-github_token). – flaxel Apr 04 '21 at 12:10
  • @flaxel it doesn't work. I created a new personal access token with read, write package permissions, but i get the same error... – Niklas Apr 04 '21 at 12:17
  • 1
    Your problem looks similar to this one: https://stackoverflow.com/questions/64124831/github-actions-401-unauthorized-when-installing-a-github-package-with-npm-or-yarn – GuiFalourd Apr 04 '21 at 14:48
  • @Niklas - Did you manage to resolve your issue? If yes, how did you resolve it. TIA. – LearnToLive Aug 06 '21 at 17:28

1 Answers1

0
  "publishConfig": {
    "registry": "https://npm.pkg.github.com/"
   },

My working configuration does not include my organization name in the registry.

Romain Prévost
  • 513
  • 2
  • 12