-
-
Notifications
You must be signed in to change notification settings - Fork 109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: "Cannot find module" error for dependency that is a peerDep of a first-party package #1092
Comments
In our case (I was looking through our lockfile) peer dependencies are not ending up encoded in the leaf package. Dev Dependencies are. A common pattern in the JS ecosystem is to declare things as peer that you expect an app to declare when they use your package and then redeclare your deps as developer deps so your tools don't yell at you. This avoids nested structures because very rarely can libraries dictate what versions apps end up with. The reason declaring as dependencies fixes it is because our lockfile then encodes the dependencies. What's odd though is that some of our 3rd party dependencies specify peerDependencies in the lockfile. It looks like workspace packages don't encode peer dependencies. Only dev dependencies and actual dependencies. Some helpful links potentially from searching |
One thing I wanted to add to this is that we set the If not, I plan to make a repro here. |
There seems to be something fishy with a first-party dependency declaring both a I got a repro up in https://github.com/sjbarag/rules_js-peer-and-dev-dep-ignored , which uses only |
Ah, okay so there's a workaround using pnpm.packageExtensions that seems safe. It's unfortunate that it's required, but it should help with any first-party dependencies that have peer+dev dependencies.
// packages/leaf/package.json
{
"name": "leaf",
"version": "1.2.3-dunno",
"devDependencies": {
"is-odd": "*",
- "left-pad": "^1.3.0"
},
"peerDependencies": {
"left-pad": "^1.3.0"
}
}
// package.json
{
"name": "some-workspace",
"version": "0.0.1-workspace-package",
+ "pnpm": {
+ "packageExtensions": {
+ "leaf@*": {
+ "devDependencies": {
+ "left-pad": "^1.3.0"
+ }
+ }
+ }
}
}
Hope this helps 😃 |
I believe there still is a bug in rules_js. I made my own minimal repro: https://github.com/jfirebaugh/rules_js-1p-peer-dep. |
@alexeagle Sorry I missed your comment. I haven't tried that workaround, but FWIW I'd view it as definitely just a workaround and not a valid-from-first-principles approach. So even if that works I'd still argue that there's a bug in |
Discussion from Slack: rules_js deviates from pnpm behavior. If you have a dep "first-party": "workspace:*", pnpm will link node_modules/first-party to the source dir for first-party. Whereas rules_js links it to the virtual store choose whether you want the symlink to point to the virtual store, like how the package would behave as a 3p dep (use npm_package) or to point to the source tree (use js_library) @gregmagolan see this wiring work with rules_js with Bazel 6+ since we now have undeclared symlinks so we could define the bazel-bin/app/node_modules/component-lib symlink to be ../../component-lib and instead of an npm_package targets for the 1p dep, users would create a js_library target that would include what they want in the package as well as the :node_modules target to get the transitive deps |
What's the thought process behind treating these things as different? Seems confusing for packages that are depended on by multiple targets to be considered a |
Also one other thought on this that our company will hit if everything ends up in |
A principled fix for this issue coming in #1646 |
@gregmagolan is this resolved with #1646 landed? |
Yes and no. #1646 should allow users to resolve this if they switch to linking with |
Now that 2.0 is shipping, marking this complete. |
What happened?
We have two
rules_js
-based libraries; let's call themleaf
andconsumer
.consumer
depends onleaf
, and each have a set of third-party dependencies. Applications might choose to depend on either or both. Our expectation is that we should be able to do the following:I’m trying to set up just the two libraries right now, using essentially the
package.json
files above. However, when I do all thepnpm install
s and then run the Jest tests inconsumer
(bazel test //path/to/consumer/src:test
), I get the following two errors in the output:Changing all of
consumer
’s peerDeps/devDeps to (regular) deps doesn’t fix anything. Changing all ofleaf
’s peerDeps to (regular) deps does fix it, since then it can find its own dependencies, but this doesn’t seem to us like the right philosophical approach for a monorepo.It also seems odd that utils has itself in its own node_modules, and we’re not sure why that would be.
Are the first-party package's peerDeps not getting properly passed along the Bazel graph?
Version
Development (host) and target OS/architectures: Running on macOS
Output of
bazel --version
:bazel 6.2.0Version of the Aspect rules, or other relevant rules from your
WORKSPACE
orMODULE.bazel
file: We're running off commit8dc6c8be10a44900408c26935b6d7182253a0b2f
.Language(s) and/or frameworks involved: TS and Jest
How to reproduce
No response
Any other information?
No response
The text was updated successfully, but these errors were encountered: