Yarn: npm publish inside yarn run sometask fail with "npm ERR! code ENEEDAUTH"

Created on 17 Mar 2017  路  8Comments  路  Source: yarnpkg/yarn

Do you want to request a feature or report a bug?

bug as mentioned here https://github.com/yarnpkg/yarn/issues/2445#issuecomment-273284359 as a side note

What is the current behavior?

command $ yarn semantic-release will end with npm auth error if npm publish is called anywhere in the semantic-release script

If the current behavior is a bug, please provide the steps to reproduce.

  1. add npm publish to package.json scripts like this
{
  "name": "test-lerna-semantic-release",
  "version": "1.0.0",
  "scripts": {
    "semantic-release": "npm publish"
  }
}
  1. run $ yarn semantic-release you will get "npm ERR! code ENEEDAUTH"

What is the expected behavior?

npm publish should work as it's working when running script with command $ npm run semantic-release

Please mention your node.js, yarn and operating system version.

$ sw_vers
ProductName: Mac OS X
ProductVersion: 10.12.3
BuildVersion: 16D32

$ node --version
v6.9.2

$ yarn --version
0.21.3

help wanted needs-confirmation

Most helpful comment

@BYK Here to second the above comment. I ran into this yesterday attempting to setup my pipeline to publish via script in Travis rather than through the npm deployment system. It uses a yarn run script and as a result it is attempting to publish to the wrong registry as yarn hijacks the env variable npm_config_registry. Took me a while to find the issue, but thanks to the linked Lerna issue I've confirmed that is the problem. The npm_config_registry was pointing to https://registry.yarnpkg.com even if registry is set in .npmrc. This can be circumvented by adding the following to .yarnrc for anyone else that may run into this:

registry "https://registry.npmjs.org/"

All 8 comments

Yeah that is really strange case, had to run scripts that run npm publish without using **ing YARN. Ha ha. I think this is npm's protection from competitors.

Had the same issue and same workaround: that's the only command we run inside an npm run'ed script rather than yarn script.

We don't intend to support or debug this so closing. Feel free to reopen if you can determine the root cause and want to fix it.

@BYK you don't have to necessary support this specific use case, but I guess it would be nice to know what is root cause of this issue so yarn users know what limitation it has, if any.

If it's not some npm specific issue it could be easily affecting other commands within package.json scripts.

ok after quick google i have found possible explanation of what is happening check lerna discussion here https://github.com/lerna/lerna/issues/896#issuecomment-311894609 seems like yarn is setting env variable which is npm using for publishing npm_config_registry this feels like yarn issue to me.

@BYK Here to second the above comment. I ran into this yesterday attempting to setup my pipeline to publish via script in Travis rather than through the npm deployment system. It uses a yarn run script and as a result it is attempting to publish to the wrong registry as yarn hijacks the env variable npm_config_registry. Took me a while to find the issue, but thanks to the linked Lerna issue I've confirmed that is the problem. The npm_config_registry was pointing to https://registry.yarnpkg.com even if registry is set in .npmrc. This can be circumvented by adding the following to .yarnrc for anyone else that may run into this:

registry "https://registry.npmjs.org/"

@BYK you don't have to necessary support this specific use case, but I guess it would be nice to know what is root cause of this issue so yarn users know what limitation it has, if any.

Seconded, ran into this and it took way too long to figure out :/. Never expected the behavior between yarn run and npm run to be so different so was the last thing I went to look.

If you're running an npm command from inside yarn, you can use the following to strip out the problem variable added by yarn:

const environment = { ...process.env, npm_config_registry: undefined };
await dependencies.exec('npm publish', { env: environment }));
Was this page helpful?
0 / 5 - 0 ratings