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] YN0041: Invalid authentication after logging in with `yarn npm login`

See original GitHub issue
  • I’d be willing to implement a fix

Describe the bug

I attempted to publish my package via yarn npm login and yarn npm publish, but yarn failed with an unexpected error

To Reproduce

Using yarn from sources in this repo: https://github.com/justjake/quickjs-emscripten

  1. Clone https://github.com/justjake/quickjs-emscripten
  2. Try to yarn npm login
  3. Try to yarn npm publish

Screenshots

If applicable, add screenshots to help explain your problem. image

Environment if relevant (please complete the following information):

  • OS: macOS 10.14.6 (18G103)
  • Node version: v10.21.0
  • Yarn version: 2.1.1-git.20200720.906e9472

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:23 (9 by maintainers)

github_iconTop GitHub Comments

8reactions
wojtekmajcommented, Jan 17, 2022

I think I have discovered something that can push this forward.

In your GLOBAL .yarnrc.yml, you will have your tokens stored. That was my situation:

npmRegistries:
  "https://npm.pkg.github.com":
    npmAuthToken: SOME_GITHUB_TOKEN_HERE
  "https://registry.yarnpkg.com":
    npmAuthToken: NPM_PUBLISH_TOKEN_HERE

npmScopes:
  acmeinc:
    npmAuthToken: ACMEINC_GITHUB_TOKEN_HERE

it looks like npmRegistries["https://npm.pkg.github.com"].npmAuthToken took priority over npmScopes.acmeinc.npmAuthToken.

  • Removing npmRegistries["https://npm.pkg.github.com"].npmAuthToken did not resolve the issue.
  • Copying npmScopes.acmeinc.npmAuthToken value to npmRegistries["https://npm.pkg.github.com"].npmAuthToken resolved the issue.

I’m still not sure, however, why is that and how to resolve this without manually fiddling with configs.

7reactions
rosanzhengcommented, Jan 24, 2022

I just had quite a hard time with the authentication part with Yarn 3.1.0, but I found the solution to it and hope I can save someone else from the struggles I’ve been having:

Problem: My requirements were to publish one repository @organization/test1 into the GitHub NPM registry. But I was not able to install this package from another repository lying within the same organization, because I defined my .yarnrc.yml wrongly. Therefore, I received 404 errors and 401 errors when trying to install it.

Solution: Here’s what worked for me regarding the .yarnrc.yml file:

npmRegistryServer: "https://registry.yarnpkg.com"

npmScopes:
  <Your scope (case sensitive!)>:
    npmAlwaysAuth: true (optional I think)
    npmAuthToken: <Your Personal Access Token>
    npmRegistryServer: <URL to where your package is hosted, in our case it was https://npm.pkg.github.com>
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to associate registry with scope in Yarn 2 without ...
However, when I do a yarn install , I get an Invalid authentication (as an anonymous user) error for packages in that scope....
Read more >
yarn login
yarn login. Running this command will prompt you for your username and email for the npm registry. It will not ask for your...
Read more >
[RTFACT-24151] Scoped npm packages have incorrect paths ...
When publishing a scoped npm package to JFrog, the tarball URL is different ... Invalid authentication (as an anonymous user) ➤ YN0041: ...
Read more >
NPM package feed authentication problem
I try to install packages from the feed and I get this message: " Invalid authentication (as an unknown user)". Any idea on...
Read more >
Yarn invalid authentication as an anonymous user
Run yarn npm audit ejsmith03 added the bug label jdanil mentioned this issue ... Anonymous user authentication allows users to log in to...
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