Yarn fails to install from CodeArtifact

0

I am working on a npm module and I setup codeartifact. I logged in using the standard aws cli login command and then published using "yarn publish". So far so good.
When I use yarn install in my test app I get the following error:

error An unexpected error occurred: "https://artifact-6c-XXXXXXXXXX.d.codeartifact.us-east-1.amazonaws.com/npm/npm-repo/aws-sdk: Unauthenticated: request did not include an Authorization header. Please provide your credentials.".

If I do "npm install" it all works and grabs the module as well as the dependencies. I see the CodeArtifact populated with all the dependencies.

I tried deleting all lock files, node_module, yarn cache etc but npm succeeds and yarn fails. It seems it is not picking up the token.
npm version 7.15.1
yarn version 1.22.10
OS: Ubuntu 20.04.2 LTS

What am I doing wrong? I would prefer to use yarn if possible.

Edited by: AndrewPanagos on Jun 27, 2021 2:52 PM

gefragt vor 3 Jahren3899 Aufrufe
2 Antworten
0

I was able to get Yarn 2 working with AWS CodeArtifact.
Go here to instructions how to install Yarn 2. https://yarnpkg.com/getting-started/install

First I created a script that exports a variable with the CodeArtifact token.
export CODEARTIFACT_AUTH_TOKEN=aws codeartifact get-authorization-token --domain artifact-domain --domain-owner 123456789012 --query authorizationToken --output text

I created a file in the root of the repo .yarnrc.yml with the following:

yarnPath: ".yarn/releases/yarn-berry.cjs"
nodeLinker: "node-modules"
npmRegistryServer: "https://artifact-domain-123456789012.d.codeartifact.us-east-1.amazonaws.com/npm/npm-repo/"
npmAlwaysAuth: true
npmAuthToken: ${CODEARTIFACT_AUTH_TOKEN}

So now when I do yarn install it authenticates correctly against CodeArtifact.

beantwortet vor 3 Jahren
0

Thanks for posting this answer. We'll get the CodeArtifact User Guide updated with instructions for Yarn 2.

  • Carl.
profile pictureAWS
beantwortet vor 3 Jahren

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen