githubcirclecicircleci-2.0github-package-registry

Installing a GitHub Package in CircleCI


For my project, I am trying to install (not publish!) a npm package from GitHub Packages. It is hosted on a private repository, which is in an org. I have made a personal access token with the required permission to read from that repo and org. All of this works locally with the following steps:

> Username: USERNAME
> Password: TOKEN
> Email: PUBLIC-EMAIL-ADDRESS

After filling out, everything works and i can install the packge, alongside all the others hosted on the normal npm registry. Now onto the problem: I am trying to replicate the same on circleCI, but it doesnt seem to let me override the npm registry. The project includes a .npmrc file in the same folder that the package.json is located at. Here is part of the circle ci conf:

      - run:
          name: "Set NPM registry"
          command: npm config set registry https://npm.pkg.github.com/OWNER
      - run:
          name: "Authenticate with GitHub package registry"
          command: echo "//npm.pkg.github.com/:_authToken=${GITHUB_PACKAGES}" > web_ui/frontend/.npmrc
      - run:
          name: "Install frontend dependencies"
          command: npm run deps-frontend

GITHUB_PACKAGES is just an env variable stored in circleCI.

Now the error message tells me the following:

npm ERR! code E401
npm ERR! Unable to authenticate, need: Basic realm="GitHub Package Registry"

I tried googling for it, but nothing that worked came up.


Solution

  • Can you try moving the run steps in the pre steps? Like so:

    pre:
      - npm config set registry https://npm.pkg.github.com/OWNER
      - echo "//npm.pkg.github.com/:_authToken=${GITHUB_PACKAGES}" > web_ui/frontend/.npmrc
      - npm run deps-frontend
    

    Another thing to try could be to use a different version of npm.