Yarn with private packages

yarn

#1

I’m having a problem getting yarn install to work with a private package. While I have the NPM_TOKEN setup, it seems that (based on local testing) yarn is loading .npmrc, but not looking at the NPM_TOKEN. If I locally move .npmrc out of the way, my yarn install also fails locally.

What are others doing to counter this? Generating an .npmrc from the environment variable?

Is this expected behavior on circleci?


#2

I ended up doing:

dependencies:
  pre:
    - echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc

If there is an easier way, please let me know. I’ll open an issue about the docs.


#3

@rosskevin Thank you for sharing your solution!

I will see if we can get this added to our Yarn docs.


#4

I do not know if it is really related, but I had the same issue on a specific branch. This only way to make it work was to do :

pre:
    - echo "registry=https://registry.npmjs.org/" > ~/.npmrc
    - echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" >> ~/.npmrc

I believe it might be related to the cache, we haven’t found out yet on our side, but if it can help anyone :slight_smile:


#5

I have tried all of the suggestions on here as well as following the instructions here and here but still cannot seem to auth successfully.

I have crossed checked the token I’m using within both NPM and Circle but still see the following error message

Request failed \"404 Not Found\"

I’m using the image node:8.9.3, CircleCI 2 and have the exactly following in the config file -

version: 2
jobs:
  build:
    docker:
      - image: node:8.9.3

    working_directory: ~/repo

    dependencies:
    pre:
      - echo "registry=https://registry.npmjs.org/" > ~/.npmrc
      - echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" >> ~/.npmrc

#6

Downgrading Node to v8.8.1 and adding a shell script (below) to the build steps prior to the yarn install seems to have done the trick

npm adduser <<!
$NPM_USER
$NPM_PWD
$NPM_EMAIL
!

The problem seems to occur when using any version of Node 8.9.x, and the NPM token alone does not seem to work.


#7