Skip to content
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

esbuild can't resolve workspace absolute imports #2474

Closed
shosti opened this issue Feb 17, 2021 · 3 comments · Fixed by #2476
Closed

esbuild can't resolve workspace absolute imports #2474

shosti opened this issue Feb 17, 2021 · 3 comments · Fixed by #2476

Comments

@shosti
Copy link

shosti commented Feb 17, 2021

🐞 bug report

Affected Rules

  • ts_library
  • esbuild

Is this a regression?

No.

Description

I may be configuring something wrong, but esbuild can't seem to find transitive ts_library dependencies within the workspace.

🔬 Minimal Reproduction

I have a minimal reproduction at https://github.com/shosti/bazel-rulesjs-repro. There's a top-level ts_library (:a) that includes lib/b.ts as a dependency (imported as "myworkspace/lib/b"). Running bazel build //:a succeeds, which indicates that the import paths are correct as far as tsc is concerned.

There's also an esbuild bundle (:bundle) that depends on :a. Running bazel build //:bundle fails with an import error message.

🔥 Exception or Error


 > ../../../../../execroot/myworkspace/bazel-out/k8-fastbuild/bin/a.mjs: error: Could not resolve "myworkspace/lib/b" (mark it as external to exclude it from the bundle)
    1 │ import foo from "myworkspace/lib/b";
      ╵                 ~~~~~~~~~~~~~~~~~~~

1 error

🌍 Your Environment

Operating System:

  
Ubuntu 20.10
  

Output of bazel version:

  
Build label: 3.5.0
Build target: bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Wed Sep 2 20:11:46 2020 (1599077506)
Build timestamp: 1599077506
Build timestamp as int: 1599077506
  

Rules_nodejs version:

(Please check that you have matching versions between WORKSPACE file and @bazel/* npm packages.)

  
3.2.0
  

Anything else relevant?

@shosti shosti changed the title ts_library dependencies can't be found by esbuild ts_library transitive dependencies can't be found by esbuild Feb 17, 2021
@jbedard
Copy link
Collaborator

jbedard commented Feb 17, 2021

I think it's the use of the myworkspace/ that doesn't work? I think I have other transitive deps working fine but I'm running into this workspace issue as well...

@mattem
Copy link
Collaborator

mattem commented Feb 17, 2021

Yeah this is esbuild not knowing how to resolve the absolute workspace imports, rollup_bundle gets this for free as it's called via run_node, where as esbuild gets called on the command line with a bunch of flags.

If we want to support this mode, then somewhere in here we could add a mapping in to the generated jsconfig:
https://github.com/bazelbuild/rules_nodejs/blob/stable/packages/esbuild/helpers.bzl#L78

@mattem mattem changed the title ts_library transitive dependencies can't be found by esbuild esbuild can't resolve workspace absolute imports Feb 17, 2021
@yohcop
Copy link

yohcop commented Feb 17, 2021

I was having the same problem. I renamed all my imports and removed the workspace name, but then I had errors in ts_library(), since the ts_library setup expects imports to be under the workspace name. It's also how it's described under Writing TypeScript code for Bazel

So I'd say it would need to be supported :/

As I was looking at the config, I was also wondering about generated files. Once I have a different computer I'll be able to try, but should bazel-bin/... or bazel-out/... also be included in rootDirs ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants