volta-cli / volta

Volta: JS Toolchains as Code. ⚡
https://volta.sh
Other
11.11k stars 236 forks source link

yarn workspace does not work with private packages #1202

Open hadasgazit opened 2 years ago

hadasgazit commented 2 years ago

I'm trying to install a private package using: yarn workspace @orgName/packageName add --peer @orgName/otherPackageName

and getting the error error An unexpected error occurred: "https://registry.yarnpkg.com/@orgName%2fotherPackageName: Not found".

installing in the root works just fine yarn add -W --peer @orgName/otherPackageName

I'm using Volta 1.0.5 node 16.13.1 yarn 1.22.17

Please advise, thank you.

charlespierce commented 2 years ago

Hi @hadasgazit, thanks for the question! I suspect this may be a bug in how yarn workspaces locates the registries. Once the expected program is located and launched (in this case yarn), Volta doesn't have any more direct involvement. We also definitely don't mess with any sort of registry resolution for the underlying package managers.

Can you share a bit more about the directory structure of your project and which directories you are running the different commands from? It looks like in the failed case, yarn is trying to locate the private package in the public registry.yarnpkg.com (which understandably fails). Is there a .npmrc or .yarnrc file somewhere in the workspace that maybe is available in some cases but not in others?

hadasgazit commented 2 years ago

@charlespierce Im running this command in Monrepo, that has the .npmrc with the content of //registry.npmjs.org/:_authToken=${NPM_TOKEN}

I'm running the command from the root of the project. The package.json in the root has the entry "volta": { "node": "16.13.1", "yarn": "1.22.17" }

while the inner package.json (inside packages/packageName) has the entry: "volta": { "extends": "../../package.json" }

Another note is that yarn workspace command in the same project worked when we did not used Volta to manage versions (used NVM)

charlespierce commented 2 years ago

Very odd! I don't immediately see anything about how Volta runs yarn that would cause this kind of issue (that's not at all to say it's not Volta, just that it's not clear what's going on). Is it possible you were using a different version of Yarn when running the command through nvm?

The reason I ask is that the .npmrc file has an entry for registry.npmjs.org, while the error is talking about registry.yarnpkg.com, which reminds me of a long-standing bug I've fought with before where Yarn doesn't respect the .npmrc settings when it's called recursively (see this closed PR for some of the background: https://github.com/yarnpkg/yarn/pull/5825).