[Bug]: issue calculating single versions of a dependency with `public_hoist_packages`
What happened?
I have a single package in my pnpm workspace that depends on @storybook/[email protected]. Outside of rules_js, if i do a pnpm why on that dependency in the package that has it I get
❯ pnpm why @storybook/addon-docs
Legend: production dependency, optional only, dev only
@company/[email protected] /Users/davidaghassi/repo/web/package
devDependencies:
@storybook/addon-docs 6.5.13
However, if I have the following in my npm_translate_lock I get an error
public_hoist_packages = {
"@storybook/addon-controls": [""],
"@storybook/addon-docs": [""],
"@storybook/addon-google-analytics": [""],
"@storybook/addon-links": [""],
"@storybook/addons": [""],
"@storybook/api": [""],
"@storybook/builder-webpack5": [""],
"@storybook/client-api": [""],
"@storybook/components": [""],
"@storybook/core-events": [""],
"@storybook/manager-webpack5": [""],
"@storybook/react": [""],
"@storybook/theming": [""],
},
The error being
ERROR: Error computing the main repository mapping: no such package '@rh_pnpm_workspace_deps//':
Invalid public hoist configuration with multiple packages to hoist to '/node_modules/@storybook/addon-docs': ["@storybook/[email protected]_-380341690", "@storybook/[email protected]_-380252348"]
Trying selecting a specific version of '@storybook/addon-docs' to hoist in public_hoist_packages. For example '@storybook/[email protected]_-380341690':
public_hoist_packages = {
"@storybook/[email protected]_-380341690": [""]
}
This is the only dependency that experiences this. If I remove this, it works. I have to pick a version for this to work overall. Without this, I can't build with storybook v6 under rules_js.
This also was hard to track down because I didn't realize this part of the npmrc was not automatically read (silently passes with no warning or error)
Version
Development (host) and target OS/architectures:
Output of bazel --version: 6.3.0
Version of the Aspect rules, or other relevant rules from your
WORKSPACE or MODULE.bazel file:
rules_js - 8e66e6ac47b1b65af6efdb5766b2dbb137065045
Language(s) and/or frameworks involved:
How to reproduce
I will have to find a repro, this is an internal repo.
Any other information?
No response
So I did find a root cause of this. It turns out that even though I thought I had one package in the workspace that specified that dep, I had two. They were identical version in the package.json, however they had different peer deps. When looking in our pnpm-lock.yaml I found these two different entries
/@storybook/[email protected](@babel/[email protected])([email protected])([email protected])([email protected])([email protected])([email protected])([email protected]):
/@storybook/[email protected](@babel/[email protected])([email protected])([email protected])([email protected])([email protected])([email protected])([email protected]):
Notice the webpack versions were different. As such, we were getting different hash values. By aligning that webpack version, the lockfile deduped and it fixed this bug.
Ultimately, I believe the ask is to have better error handling in this case.
I hit this last week also. But the error message does provide a string you can copy-paste for the package@version key in that dict. I guess a very small improvement to that error message could close this.