Search code examples
node.jsdockernpmcontinuous-integrationyarnpkg

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.


Solution

  • 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.