Yarn add - Private package - 404 Not Found

Viewed 1555

I want to install a private package hosted on an internal Gitlab with Yarn. So, I configured my .npmrc with this informations :

@mypackage:registry=https://gitlab.intra/api/v4/packages/npm/
//gitlab.intra/api/v4/projects/819/packages/npm/:_authToken=xxxxx
//gitlab.intra/api/v4/packages/npm/:_authToken=xxxxx
always-auth=true

When I attempt to install the package with yarn add @mypackage/lib-node-client, Yarn give me an error :

Trace: 
  Error: https://gitlab.intra/api/v4/projects/725/packages/npm/@mypackage/lib-node-common/-/@mypackage/lib-node-common-21.7.1.tgz: Request failed "404 Not Found"
      at ResponseError.ExtendableBuiltin (/usr/lib/node_modules/yarn/lib/cli.js:696:66)
      at new ResponseError (/usr/lib/node_modules/yarn/lib/cli.js:802:124)
      at Request.<anonymous> (/usr/lib/node_modules/yarn/lib/cli.js:67062:16)
      at Request.emit (node:events:369:20)
      at Request.module.exports.Request.onRequestResponse (/usr/lib/node_modules/yarn/lib/cli.js:141640:10)
      at ClientRequest.emit (node:events:369:20)
      at HTTPParser.parserOnIncomingClient (node:_http_client:646:27)
      at HTTPParser.parserOnHeadersComplete (node:_http_common:129:17)
      at HTTPParser.execute (<anonymous>)
      at TLSSocket.socketOnData (node:_http_client:512:22)

So, Yarn can't find the URL : https://gitlab.intra/api/v4/projects/725/packages/npm/@mypackage/lib-node-common/-/@mypackage/lib-node-common-21.7.1.tgz

If I try to get this on my browser, I can download the package...

If anyone can help me please, thank's for all :)

2 Answers

In your .npmrc file, you tell how to connect to GitLab for the project 819. The error is about the project 725. GitLab simply refuse the connexion.

Try with

@mypackage:registry=https://gitlab.intra/api/v4/packages/npm/
//gitlab.intra/api/v4/projects/725/packages/npm/:_authToken=xxxxx
//gitlab.intra/api/v4/projects/819/packages/npm/:_authToken=xxxxx
//gitlab.intra/api/v4/packages/npm/:_authToken=xxxxx
always-auth=true

We had a gitlab private package registry, and was constantly getting this error. npm i @placeholder/package-name works fine, but yarn add @placeholder/package-name was giving 404 errors.

I tried all possible solutions listed on this thread. At last, there was a section in gitlab on troubleshooting yarn installation [1]. It said,

try adding this to your .npmrc file (and replace <your_token> with your personal access token or deploy token):

//gitlab.example.com/api/v4/projects/:_authToken=<your_token>

Our previous .npmrc looked like this

save-exact=true
unsafe-perm=true
@placeholder:registry=https://gitlab.com/api/v4/packages/npm/
//gitlab.com/api/v4/packages/npm/:_authToken=${PLACEHOLDER_TOKEN}

With the above new line addition, it looked like this,

save-exact=true
unsafe-perm=true
@placeholder:registry=https://gitlab.com/api/v4/packages/npm/
//gitlab.com/api/v4/packages/npm/:_authToken=${PLACEHOLDER_TOKEN}
//gitlab.com/api/v4/projects/:_authToken=${PLACEHOLDER_TOKEN}

With that addition, yarn add @placeholder/package-name worked fine.


[1] https://docs.gitlab.com/ee/user/packages/npm_registry/#error-running-yarn-with-the-package-registry-for-npm-registry

Related