dockerdocker-composecontainers

Getting 404 When trying to install a private package on my container


I am trying to install a private package (@some-private-package) in my container. I am installing the package in the container via docker compose using this command

docker-compose run container yarn add @some-private-package

but whenever I run the command, I get this

[1/4] Resolving packages...
error An unexpected error occurred: "https://registry.npmjs.org/@some-private-package: Not found".
info If you think this is a bug, please open a bug report with the information provided in "/home/node/app/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.

However, it does work when I run the yarn add command locally.
I can see the .yarnrc file in the container as well as the NPM_TOKEN so I am not still sure why I am getting this error

What could be wrong?

I am passing all content to my container via a docker compose yaml which is defined as below

x-container: &container
  build:
    context: '../container'
    args:
      NPM_TOKEN: '${NPM_TOKEN}'
      NODE_ENV: 'development'
  depends_on:
    - mysql
  links:
    - 'gateway:local'
  hostname: container
  env_file:
    - config/secrets/mysql.env
  volumes:
    - '../container:/home/node/app:cached'

I have tried deleting and rebuilding the container without cache but the issue still persists


Solution

  • Things you can do to troubleshoot or fix this issue

    1. Your .yarnrc file might not being copied to your docker container. Confirm that you have something like this in your docker file COPY .yarnrc package.json yarn.lock {Your WORKDIR}.
    2. Confirm the NPM_TOKEN actually exist in your container by doing docker-compose run container echo $NPM_TOKEN.
    3. If the error still persist instead of doing docker-compose run container yarn add @some-private-package, trying running the container and then launching a terminal in docker-desktop. In the terminal do export ${YOUR_NPM_TOKEN(The actual token)}, and after run yarn add @some-private-package.

    Let me know if you need any other help