rules_js
rules_js copied to clipboard
Typescript fails under Bazel in pnpm workspace, but not fail without Bazel
Hi team, thanks for this great repository!
I recently moved from ruled_nodejs
but found a weird bug:
MVCE repo: https://github.com/tamuhey/rules-js-bug
In this repository, bazel build foo
fails, but pnpm tsc
doesn't.
I tried to create a more small example, but it seems that pnpm workspace relates to this issue.
Could someone help me to understand why this happens, and how to solve this issue? Thanks!
The failure,
src/Foo.tsx(4,4): error TS2322: Type '{ children: Element; as: string; }' is not assignable to type 'Omit<never, PropsWeControl>'.
Property 'children' is incompatible with index signature.
Type 'Element' is not assignable to type 'never'.
looks related to this issue,
https://github.com/tailwindlabs/headlessui/discussions/1421
Most likely related to hoisting differences between pnpm outside of bazel and rules_js. rules_js, for example, can't allow for phantom dependencies that pnpm allow for in its node_modules/.pnpm/node_modules
folder since all dependencies need to be explicit under Bazel and every npm package implicitly depending on every other npm package would not allow for lazy fetching and linking.
@gregmagolan is there some way we could get pnpm to run in a "bazel-like" mode so it's easier to know why it repros only under Bazel?
If every JS rule included node_modules/.pnpm/node_modules
as an extra dependency, that wouldn't make every npm package implicitly depend on every other, is there some solution there?
Thanks for the comment! I'm not very familiar with phantom dependency
, but is it related to pnpm workspace?
The error doesn't occur without pnpm workspace.
Also, is there any workaround for this specific problem?
I think you already know why this is failing but I just wanted to add that my build also fails when using pnpm workspaces with a similar cryptic error.
error TS2742: The inferred type of 'options' cannot be named without a reference to '.aspect_rules_js/@[email protected]/node_modules/@protobuf-ts/runtime'. This is likely not portable. A type annotation is necessary.
Not using workspaces fixes it.
https://github.com/aspect-build/rules_js/commit/7377f2d0387cc2a9251137929b1c53ccdb3fbcf0 added the doc to show how to make pnpm show the same result outside of Bazel.