Npm install from gitlab package registry not working

I’ve published an npm package to my private group. This is the link for npm: https://gitlab.com/api/v4/packages/npm/@coeng2020%2Fservice-fetcher

using npm i @coeng2020/service-fetcher i get a 404 not found message.

But when I paste the link in a broswer, I get a 304 with all the required info for npm.

Is there something Im missing from my setup?

i’ve also ran this command already in my repo: echo @coeng2020:registry=https://gitlab.com/api/v4/packages/npm/ >> .npmrc

Please help

For private projects make sure you’ve also setup authentication to the registry for it to be able to resolve your project and package: https://docs.gitlab.com/ee/user/packages/npm_registry/#authenticate-with-a-personal-access-token-or-deploy-token

I have published the npm package to gitlab.com without a problem.

In another private project, I want to consume this npm package. It works locally after setting up the .npmrc with my personal access token accordingly and when executing npm install @my-org/project_a.

However, it fails when the gitlab pipeline wants to install it with the following messages:

npm ERR! code E404
62npm ERR! 404 Not Found - GET https://gitlab.com/api/v4/projects/<id_of_project_a>/packages/npm/@my-org/project_a/-/@my-org/project_a-0.0.7.tgz
63npm ERR! 404 
64npm ERR! 404  '@my-org/project_a@https://gitlab.com/api/v4/projects/<id_of_project_a>/packages/npm/@my-org/project_a/-/@my-org/project_a-0.0.7.tgz' is not in the npm registry.

I have set up the .npmrc in the gitlab-ci.yml as well and I have tried out several auth keys, including my personal access token and the $CI_JOB_TOKEN . I have also cleared the gitlab runner cache several times.

Accessing the url https://gitlab.com/api/v4/projects/<id_of_project_a>/packages/npm/@my-org/project_a/-/@my-org/project_a-0.0.7.tgz also works via the browser.

Do you have an idea why it works locally and fails on gitlab ci cd even with the same access tokens and .npmrc ?

How can I debug this?

Hello
I got same error with a private package. How did You manage to solve It?
Thanks so much

Hi Pavel,

I managed to get it to work with a separate personal access token. Here is what i did:

  • Create a personal access token from Gitlab with the permissions read_api and read_registry.

  • Expose this personal access token in the gitlab ci pipeline through a variable

  • Ensure the .npmrc has the following content:

# Set URL for your scoped packages, e.g. package with name `@my-org/my-package` will use this URL for download.
"@your_org_scope:registry"="https://gitlab.com/api/v4/packages/npm/"

# Add the token for the scoped packages URL. This will allow you to download.
# Make sure you replace ${GITLAB_AUTH_TOKEN} with the personal access token copied earlier or create a local environment variable (this is recommended) named GITLAB_AUTH_TOKEN with the token copied earlier as the value.
"//gitlab.com/api/v4/packages/npm/:_authToken"="${GITLAB_AUTH_TOKEN}"

# Add token for uploading to the registry.
# NOTE: Currently, the project id is XXXXXX. If this changes, you will need to adjust this accordingly.
"//gitlab.com/api/v4/projects/<<project_id>>/packages/npm/:_authToken"="${GITLAB_AUTH_TOKEN}"

And then npm install should work in the gitlab as well.

I was not able to get it working with the CI_TOKEN

Awesome. That did the trick!
Thanks so much for your help