Open xenobytezero opened 4 years ago
yarn npm whoami --scope
not picking up the correct login was fixed in https://github.com/yarnpkg/berry/pull/1943 but it hasn't been released yet, you can test out the version from master using yarn set version from sources
@merceyz Does #1943 only fix whoami
issues or for all authentication with scoped packages? I'm just using whoami
as an example rather than using yarn npm publish
which is producing the same errors?
@merceyz I've just run yarn set version from sources
and I'm getting the same behaviour with a scope where the auth token is in my user .yarnrc
C:\Projects\__\tool>yarn npm whoami --scope obsidian --publish
➤ YN0033: No authentication configured for request
➤ YN0000: Failed with errors in 0s 3ms
Hi! 👋
This issue looks stale, and doesn't feature the reproducible
label - which implies that you didn't provide a working reproduction using Sherlock. As a result, it'll be closed in a few days unless a maintainer explicitly vouches for it or you edit your first post to include a formal reproduction (you can use the playground for that).
Note that we require Sherlock reproductions for long-lived issues (rather than standalone git repositories or similar) because we're a small team. Sherlock gives us the ability to check which bugs are still affecting the master branch at any given point, and decreases the amount of code we need to run on our own machines (thus leading to faster bug resolutions). It helps us help you! 😃
If you absolutely cannot reproduce a bug on Sherlock (for example because it's a Windows-only issue), a maintainer will have to manually add the upholded
label. Thanks for helping us triaging our repository! 🌟
This issue is difficult to reproduce considering the nature of it.
Can anyone provide pointers for how to keep this issue open? I'm still seeing the issue, and have had to move back to NPM7 to continue working.
https://github.com/yarnpkg/berry/issues/1998#issuecomment-712084046 the auth token is in my user .yarnrc
Do you mean .yarnrc.yml
? .yarnrc
isn't used by V2
Anyways, I can't reproduce this
Do you mean .yarnrc.yml? .yarnrc isn't used by V2
I'm not the original reporter but I'm almost sure that he meant .yarnrc.yml
. I'm just tired to set up the publishing of scoped packages to a private repository and I've hit the exact same problem, as the original requestor described.
yarn npm login --scope XXX
where XXX is my scope, which is configured via npmScopes, logins successfully and adds npmAuthToken into .yarnrc.yml
in $HOME but yarn npm whoami --scope XXX
fails to authorize unless I copy npmAuthToken from .yarnrc.yml
in $HOME into .yarnrc.yml
in the project directory. Likewise publish doesn't work as well unless npmAuthToken is copied into .yarnrc.yml
in the project directory. Basically, I've done exactly the same steps as @xenobytezero described and I've got the exact same results.
This is reproducible with the latest version yarn 2.4.1
Can confirm I meant .yarnrc.yml
i am not using a custom registry, though i am using scoped packages inside a yarn 2 workspace. as described above, when i run yarn npm login --scope acusti
, the resulting npmAuthToken
is written to ~/.yarnrc.yml
, but when i then try to run yarn npm publish
, i get YN0033 (which doesn’t have an entry in the error codes page):
YN0033: No authentication configured for request
however, if i copy the npmAuthToken
and add it as a top-level item in the workspaces’ top-level .yarnrc.yml
file, npm publish
works without error.
note that i had to yarn set version from sources
to resolve #2232, so my yarn version is the following:
$ yarn --version
2.4.0-git.20210324.hash-a307bddb
I'm hitting the same issue with GitHub Packages. The following is specified in <project>/.yarnrc.yml
:
npmScopes:
myorg:
npmRegistryServer: "https://npm.pkg.github.com"
To install the dependencies of the project, I first do the following in <project>
:
yarn npm login --scope myorg
This puts the following in ~/.yarnrc.yml
:
npmScopes:
myorg:
npmAuthToken: ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
After logging in, if I do the following in <project>
...
yarn config get npmScopes
...I see this:
{
myorg: {
npmAlwaysAuth: false,
npmAuthIdent: null,
npmAuthToken: null,
npmPublishRegistry: null,
npmRegistryServer: 'https://npm.pkg.github.com'
}
}
If I remove npmScopes
from <project>/.yarnrc.yml
, I instead see this:
{
myorg: {
npmAlwaysAuth: false,
npmAuthIdent: null,
npmAuthToken: '********',
npmPublishRegistry: null,
npmRegistryServer: 'https://registry.yarnpkg.com'
}
}
This leads me to believe that the configuration merging is not working for npmScopes
for some reason. What I'd expect to see is this:
{
myorg: {
npmAlwaysAuth: false,
npmAuthIdent: null,
npmAuthToken: '********',
npmPublishRegistry: null,
npmRegistryServer: 'https://npm.pkg.github.com'
}
}
That is, npmRegistryServer
should be sourced from <project>/.yarnrc.yml
and npmAuthToken
should be sourced from ~/.yarnrc.yml
. Is that what the maintainers believe should happen as well or am I holding this thing wrong?
Looking into the unit tests for the Configuration
class it looks like the nested values of npmScopes
are expected to be overridden: https://github.com/yarnpkg/berry/blob/%40yarnpkg/core%2F2.4.0/packages/yarnpkg-core/tests/Configuration.test.ts#L160-L189
From the "should overwrite map properties" unit test the following two config files:
// global config
{
npmRegistryServer: `https://foo.server`,
npmScopes: {
foo: {
npmAuthToken: `token for foo`,
},
},
}
// project config
{
npmRegistryServer: `http://bar.server`,
npmScopes: {
foo: {
npmAlwaysAuth: true,
},
bar: {
npmAlwaysAuth: true,
},
},
}
Will result in configuration.get('npmScopes').get('foo').get('npmAuthToken') === null
even though npmAuthToken
is defined in the global config.
The merge logic was added in #1859 and the description mentions this exact case:
I've opted for only merging maps because merging maps makes sense. For shape configuration types it doesn't really make sense. What would the expected result be when merging
npmScopes: foo: npmAuthIdent: someIdent==
into
npmScopes: foo: npmAuthToken: a-token
? The object would have both ident and token, so how do we decide which one to take? What if the configs were turned around?
We could add a function on the
ShapeSettingsDefinition
type to perform this merge, but I'm not sure that's worth it. Wouldn't that always come down to not merging anyway? I mean: why would you want to replace thenpmRegistryServer
for a scope but keep thenpmPublishRegistry
and the configured authentication? If you want to configure auth and registry separately for a scope we already provide a way to do so vianpmRegistries
.
This behavior is unexpected to users and does not match how the documentation describes how to utilize yarn npm login --scope myorg
. A deep merge should be added for these nested properties
Run yarn config set --home "npmRegistries['<npmRegistryServer>'].npmAuthToken" "<npmAuthToken>"
with the vales of your npmRegistryServer
and npmAuthToken
This will add the auth token associated with the NPM registry URL to the global ~/.yarnrc.yml
file.
npmRegistries:
"https://npm.pkg.github.com":
npmAuthToken: ffffffff-ffff-ffff-ffff-ffffffffffff
+1 for experiencing this issue on my end. If its not technically a bug it is certainly not the behaviour I expected - in yarnv1 or npm the authToken for scope gets merged as expected and installs/publishes work fine.
Workaround
Run
yarn config set --home "npmRegistries['<npmRegistryServer>'].npmAuthToken" "<npmAuthToken>"
with the vales of yournpmRegistryServer
andnpmAuthToken
This will add the auth token associated with the NPM registry URL to the global
~/.yarnrc.yml
file.npmRegistries: "https://npm.pkg.github.com": npmAuthToken: ffffffff-ffff-ffff-ffff-ffffffffffff
@rachel-church your workaround works a charm in the meantime, thank you
It's difficult to provide a reproduction for this issue, considering that it requires a custom NPM registry, but I have described as much as possible.
Describe the bug
I have a Yarn 2 Workspaces projects, under the scope 'obsidian' set up like the following
My
.yarnrc.yaml
looks like the following (with redactions)I am at the point where I'm ready to publish, and started going through the
yarn npm login
flow, and cannot seem to successfully login to a custom registry with a scope and successfully publish.To Reproduce
I now have the following in my user
.yarnrc.yaml
All seems good at this point. Lets try and do a whoami to confirm the login
From the subpackages?
Lets look at the yarn config that combines the project and the user settings
Looks like it's not picking up the scoped
npmAuthToken
from the user.yarnrc
? Normally the auth token shows up as*********
in the list.We are now in non-useful debug territory, but lets try dumping the
npmAuthToken
in the project.yarnrc
for this scopeTry again?
Config list?
So it's picking up the npmAuthToken now but not using it?
Finally what if we just add the auth token to the top level of the
.yarnrc
?Try again
Looks like thats the only way to get this to work?
I can confirm that trying to
yarn npm publish
produces the same results as usingyarn npm whoami
, can only get it to work with putting thenpmAuthToken
at the root of the project.yarnrc
Environment if relevant (please complete the following information):