yarn icon indicating copy to clipboard operation
yarn copied to clipboard

yarn publish uses wrong credentials

Open bgotink opened this issue 8 years ago • 3 comments

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

What is the current behavior?

When publishing yarn uses the authentication of the registry configured in yarnrc, not the registry configured in publishConfig.registry in the package.json.

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

  1. Create a package with a registry in the yarnrc and a different registry in the package.json's publishConfig
  2. Configure npmrc with authentication scoped to the normal registry and a different authenciation scoped to the registry used in publishConfig
  3. Try to publish
  4. See publish failure, debug requests and note that the authorization header for the user configured in the regular registry

Our config:

# .yarnrc
registry "https://nexus.internal/nexus/content/groups/my-npm-group/"
# .npmrc
//nexus.internal/nexus/content/groups/my-npm/:username=some-user
//nexus.internal/nexus/content/groups/my-npm/:_password=some-pwd
//nexus.internal/nexus/content/groups/my-npm/:always-auth=true
//nexus.internal/nexus/content/groups/my-npm/:[email protected]
# .npmrc used by Jenkins in NPM_CONFIG_USERCONFIG

//nexus.internal/nexus/content/repositories/my-npm-releases/:username=other-user
//nexus.internal/nexus/content/repositories/my-npm-releases/:_password=other-pwd
//nexus.internal/nexus/content/repositories/my-npm-releases/:always-auth=true
//nexus.internal/nexus/content/repositories/my-npm-releases/:[email protected]
{
  "//": "...",
  "publishConfig": {
    "registry": "https://nexus.internal/nexus/content/repositories/my-npm-releases/"
  }
}

What is the expected behavior?

Yarn should use the authentication scoped to the publishConfig registry, not the regular registry

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

  • node 8.11.3
  • yarn 1.9.4
  • macOS High Sierra

bgotink avatar Aug 10 '18 09:08 bgotink

@bgotink A workaround for now seems to pass --registry argument to yarn publish instead of using publishConfig.

Fer0x avatar Sep 18 '18 11:09 Fer0x

We don't run yarn publish directly (we use lerna) so I don't think we can make that happen. I've worked around it by telling lerna to use npm to publish, but I'd much rather not use npm at all.

bgotink avatar Sep 19 '18 07:09 bgotink

@bgotink We also use lerna. In root package.json we have a task "release": "lerna run release". And in each package we have a task similar to this "release": "yarn build && yarn publish --non-interactive --registry http://myregistry.com/" This tasks and using token in .npmrc allow us to publish packages with our CI.

Fer0x avatar Sep 19 '18 08:09 Fer0x