Yarn: Yarn publish command not reading password from .yarnrc

Created on 13 Jul 2017  路  7Comments  路  Source: yarnpkg/yarn

Do you want to request a feature or report a bug?
Can yarn publish step read password from .yarnrc file? I would like to publish my package as part of my continuous integration process
What is the current behavior?
yarn doesn't read password from .yarnrc file, but it does reads username. Is there any other alternative since the continuous integration process cannot work with interaction.

What is the expected behavior?
Read credentials from yarnrc file
Please mention your node.js, yarn and operating system version.
yarn 0.27.2
node 6.9.4
mac 10.11.3

Most helpful comment

@gutenye I ran into this problem as well. Because of the underscore it needs to be defined with surrounding quotes like that:

"_authToken" <TOKEN>

Or you can set it via yarn config set _authToken <TOKEN> which does it for you.

All 7 comments

Looking at the code, it seems like _username and _password should work: https://github.com/yarnpkg/yarn/blob/3bfa1e3d6303c58aed9660e1a2af3a6d6f030bce/src/registries/npm-registry.js#L224-L243

You could try an auth token in _authToken instead. Log in to npm or Yarn then copy the auth token it saves to the .yarnrc or .npmrc.

Either password or _password didn't work.

How do I get the authentication token, can you please provide me some steps. I tried the command:
"yarn login", but it didn't provide any authentication token?

Try npm login, enter your username and password, and then look in ~/.npmrc. It should have a line like this:

//registry.npmjs.org/:_authToken=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx

Update your CI environment to write this to ~/.npmrc. I don't think yarn login does auth the same way, but it does support npm auth tokens so this should work with Yarn too. Using an auth token is more secure as it does not expose your password (so there's no possibility for your password to leak)

I have same problem, after add _authToken to ~/.yarnrc got this error:

error An unexpected error occurred: "Unknown token 8:1 in /Users/guten/.yarnrc".

@gutenye I ran into this problem as well. Because of the underscore it needs to be defined with surrounding quotes like that:

"_authToken" <TOKEN>

Or you can set it via yarn config set _authToken <TOKEN> which does it for you.

I have the same problem as well (_authToken in this case).

After doing some debugging it looks like NpmRegistry#config only contains values from .npmrc when NpmRegistry#getAuth is called. So, it only works if _authToken, _auth, _password etc. are defined in .npmrc.

Nevertheless at the end of YarnRegistry#loadConfig the config object of that instance is populated as expected but there is also another instance of NpmRegistry which is used in this yarn publish case. I have no idea if this is the intended behavior.

This has been reproduced with latest yarn v1.6.0.

@akloeber Thanks for the ""(double quotes) solution. I was breaking my head for like 8 hours. Adding the double quotes around _auth fixed it :)

Was this page helpful?
0 / 5 - 0 ratings