question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug]: Yarn 2 has broken scoped authentication functionality since 2.2.0 version

See original GitHub issue

Self-service

  • I’d be willing to implement a fix

Describe the bug

Since yarn 2.2.0 version

yarn npm login --scope myCompany

Doesn’t work as previous version, which has a correct behavior.

I used to Yarn 2.1.1 in our repository but when upgrade Yarn till 2.4.3 problem appears. Here are steps and results with two different version of Yarn.

To reproduce

Yarn 2.1.1

Prerequisites

~/repository/.yarnrc.yml

npmScopes:
 myCompany:
  npmAlwaysAuth: true
  npmRegistryServer: "https://repo.myCompany.com/api/npm/npm-bld"

yarnPath: .yarn/releases/yarn-2.1.1.cjs

Steps

yarn npm login --scope myCompany

Creates

~/.yarnrc.yml

npmRegistries:
  "https://repo.myCompany.com/api/npm/npm-bld":
  npmAuthToken: <token>

yarn config

Output

➤ YN0000: npmRegistries Map(1) 
    { 'https://repo.myCompany.com/api/npm/npm-bld' => Map(3) 
        { 'npmAlwaysAuth' => false, 'npmAuthIdent' => null, 'npmAuthToken' => '********' } 
    }
➤ YN0000: npmRegistryServer 'https://registry.yarnpkg.com'
➤ YN0000: npmScopes Map(1) 
    { 'myCompany' => Map(5) 
        { 'npmAlwaysAuth' => true, 
        'npmAuthIdent' => null, 
        'npmAuthToken' => null,
        'npmPublishRegistry' => null, 
        'npmRegistryServer' => 'https://repo.myCompany.com/api/npm/npm-bld' 
        }
    }

yarn add @myCompany/coolPackage

Result

Successful authentication and downloading @myCompany/coolPackage package from scoped repository.

Yarn 2.4.3

Prerequisites

~/repository/.yarnrc.yml

npmScopes:
 myCompany:
  npmAlwaysAuth: true
  npmRegistryServer: "https://repo.myCompany.com/api/npm/npm-bld"

yarnPath: .yarn/releases/yarn-2.4.3.cjs

Steps

yarn npm login --scope myCompany

Creates

~/.yarnrc.yml

npmScopes:
  myCompany:
    npmAuthToken: <token>

yarn config

Output

➤ YN0000: npmRegistries                 Map(0) {}
➤ YN0000: npmRegistryServer             'https://registry.yarnpkg.com'
➤ YN0000: npmScopes                     Map(1) 
    { 'myCompany' => Map(5) 
	    {'npmAlwaysAuth' => true, 
		'npmAuthIdent' => null, 
		'npmAuthToken' => null, 
		'npmPublishRegistry' => null, 
		'npmRegistryServer' => 'https://repo.myCompany.com/api/npm/npm-bld' 
		} 
	}

yarn add @myCompany/coolPackage

Result

Internal Error: Invalid authentication (as an anonymous user). Package was no downloaded.

Output

➤ YN0027: @myCompany/coolPackage@unknown can't be resolved to a satisfying range:

Internal Error: Invalid authentication (as an anonymous user)
    at D (/Users/user/repository/.yarn/releases/yarn-2.4.3.cjs:2:228065)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async v (/Users/user/repository/.yarn/releases/yarn-2.4.3.cjs:2:229050)
    at async W.resolvers.getCandidates (/Users/user/repository/.yarn/releases/yarn-2.4.3.cjs:2:240795)
    at async n.getCandidates (/Users/user/repository/.yarn/releases/yarn-2.4.3.cjs:2:344518)
    at async K (/Users/user/repository/.yarn/releases/yarn-2.4.3.cjs:2:36928)
    at async /Users/user/repository/.yarn/releases/yarn-2.4.3.cjs:2:36175
    at async h (/Users/user/repository/.yarn/releases/yarn-2.4.3.cjs:2:34661)
    at async F (/Users/user/repository/.yarn/releases/yarn-2.4.3.cjs:2:35850)
    at async /Users/user/repository/.yarn/releases/yarn-2.4.3.cjs:2:39467

➤ Errors happened when preparing the environment required to run this command.

Environment

System:
    OS: macOS 11.5.2
    CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
  Binaries:
    Node: 14.4.0 - /private/var/folders/zn/v8t9q4ln6qg3xsl5z5235nfw0000gn/T/xfs-4ccbb8d6/node
    Yarn: 2.4.3 - /private/var/folders/zn/v8t9q4ln6qg3xsl5z5235nfw0000gn/T/xfs-4ccbb8d6/yarn
    npm: 6.14.13 - /usr/local/bin/npm
  npmPackages:
    jest: 26.2.2 => 26.2.2

Additional context

I suppose that the problem with lost map in ~/.yarnrc.yml according to “npmRegistries” object. Because of lost object:

npmRegistries:
  "https://repo.myCompany.com/api/npm/npm-bld":
  npmAuthToken: <token>

When I had researching this problem I found that this behavior appears in yarn 2.2.0 version.

Please return behavior of yarn 2.1.1 version.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:16
  • Comments:17 (3 by maintainers)

github_iconTop GitHub Comments

13reactions
Rushcommented, Nov 10, 2021

Reproducible and not stale.

4reactions
Rushcommented, Oct 9, 2021

Yarn is an open-source project. If you have a frustrating bug with it you really want to see fixed, I encourage you to investigate it yourselves and open a PR!

Thank you for working on Yarn but we don’t need patronizing. I’ve done my fair share of open source contributions and will contribute in the right circumstances but onboarding to a new open source project is not a trivial ask. In this case I provided a viable workaround as a contribution. The OP also did a quite detailed report which must have took time investment.

If you can’t fix it, so be be it, but I’m within my right to complain about the bug 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configuration options | Yarn - Package Manager
List of all the configuration option for Yarn (yarnrc files)
Read more >
Release Notes — Airflow Documentation
New to this release of Airflow is the concept of Datasets to Airflow, and with it a new way of scheduling dags: data-aware...
Read more >
Changelog - npm Docs
Changelog. Select CLI Version: Version 7.24.2 (Legacy Release).
Read more >
Bug listing with status UNCONFIRMED as at 2022/12/24 17 ...
Bug :128538 - "sys-apps/coreutils: /bin/hostname should be installed from coreutils not ... with dev-libs/cyrus-sasl-2.1.25-r3 - broken SASL authentication" ...
Read more >
Dataproc release notes - Google Cloud
version field,. Fixed a bug that caused a Dataproc cluster with a Dataproc Metastore service to fail the creation process, if the cluster...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found