react-nativenpmazure-devopsyarnpkg

Issues Installing Package from Private Azure DevOps Registry with Yarn


I'm trying to install a package from a private Azure DevOps registry using Yarn. I have configured my .yarnrc.yml file as follows:

npmScopes:
  mycompany:
    npmRegistryServer: https://pkgs.dev.azure.com/mycompany/_packaging/myproject/npm/registry/
    npmAlwaysAuth: true
    npmAuthToken: <my-auth-token>

When I try to add the package with:

yarn add @mycompany/mypackage

I receive the following errors:

➤ YN0027: @mycompany/mypackage@unknown can't be resolved to a satisfying range
➤ YN0041: Invalid authentication (as an unknown user)
➤ Errors happened when preparing the environment required to run this command.

The setup works fine with npm using the following .npmrc configuration:

registry=https://pkgs.dev.azure.com/mycompany/_packaging/myproject/npm/registry/
always-auth=true

; begin auth token
//pkgs.dev.azure.com/mycompany/_packaging/myproject/npm/registry/:username=mycompany
//pkgs.dev.azure.com/mycompany/_packaging/myproject/npm/registry/:_password=[ACCESS_TOKEN]
//pkgs.dev.azure.com/mycompany/_packaging/myproject/npm/registry/:email=[EMAIL]
//pkgs.dev.azure.com/mycompany/_packaging/myproject/npm/:username=mycompany
//pkgs.dev.azure.com/mycompany/_packaging/myproject/npm/:_password=[ACCESS_TOKEN]
//pkgs.dev.azure.com/mycompany/_packaging/myproject/npm/:email=[EMAIL]
; end auth token

yarn version 3.6.4 npm version 10.8.1 node version 18.20.3

Verified the Package Name: I checked that the package @mycompany/mypackage exists in the registry.

Checked Authentication Token: Confirmed that the npmAuthToken is correct and has the necessary permissions.

Manual Configuration: Tried setting the registry and authentication token manually with the following commands:


Solution

  • I have tested the same .yarnrc.yml file sample and reproduced the same issue.

    enter image description here

    To solve this issue, you can change to use the npmAuthIdent in the .yarnrc.yml file.

    Here is an example:

    npmScopes:
      mycompany:
        npmRegistryServer: https://pkgs.dev.azure.com/mycompany/_packaging/myproject/npm/registry/
        npmAlwaysAuth: true
        npmAuthIdent: ANY_USERNAME:MY_TOKEN_AS_BASE64
    

    Note: You need to convert the username:PAT to base64 format and input to the npmAuthIdent field.

    For more detailed info, you can refer to this github ticket: Azure artifacts authentication