Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install package from private registry using Yarn in Docker

I try to install packages from a private registry using yarn in a docker image, so we reuse this image in other pipelines. When I use npm everything works fine, but as soon I use yarn i get 404's.

Using NPM it is working fine:

RUN npm config set @my-scope:registry https://registry.npmjs.org && \
    npm config set //registry.npmjs.org:_authToken ${AUTH_TOKEN_PRIVATE_REGISTRY}

RUN npm i @my-scope/my-package # success!

And when using Yarn:

RUN yarn config set @my-scope:registry https://registry.npmjs.org && \
    yarn config set //registry.npmjs.org:_authToken ${AUTH_TOKEN_PRIVATE_REGISTRY}

RUN yarn add @my-scope/my-package # 404!

I'm really wondering what I'm doing wrong when using Yarn. I see quite some options to login via the CLI, which will work but I need to have the process automated.

like image 977
Robert-Jan Kuyper Avatar asked Jan 29 '26 08:01

Robert-Jan Kuyper


1 Answers

After some trials I solved it by adding 2 files: the .yarnrc and .npmrc.

The .yarnrc contains the following:

registry "https://registry.npmjs.org"

The .npmrc contains:

//registry.npmjs.org/:_authToken=[ACCESS_TOKEN]

You can now remove the yarn config set lines from Docker, and run yarn add @my-scope/foo-bar to install your package.

like image 56
Robert-Jan Kuyper Avatar answered Jan 31 '26 20:01

Robert-Jan Kuyper



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!