Skip to content

document convenient way to lay out all files in bazel-out #1771

Closed

Description

@mrmeku

🐞 bug report

Affected Rule

The issue is caused by the rule: ts_project

Is this a regression?

No

Description

Consider what happens when you try to bundle a index.js emited by ts_project.

index.js is placed in execroot/workspace/bazel-out/k8-fastbuild/bin/index.js and tries to do a relative import of a non-generated file something like ./styles.css (other common scenarios would be a local .js, or .json file)

styles.css is placed in execroot/workspace/styles.css

So the relative import fails since the bundler doesn't know how to resolve things living bazel-out vs not in bazel-out

In order to fix this sort of thing we'll either need to layout the directory structure differently or provide some documentation on ways to configure bundlers to resolve these imports.

A clear and concise description of the problem...

🔬 Minimal Reproduction

#1770

🔥 Exception or Error


ERROR in ./bazel-out/k8-fastbuild/bin/index.js
Module not found: Error: Can't resolve './styles.css' in '.../execroot/react_webpack/bazel-out/k8-fastbuild/bin'
 @ ./bazel-out/k8-fastbuild/bin/index.js 5:13-36

🌍 Your Environment

Output of bazel version:

  
Build label: 2.2.0
Build target: bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Tue Mar 3 09:26:12 2020 (1583227572)
Build timestamp: 1583227572
Build timestamp as int: 1583227572
  

Rules_nodejs version:

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

  
http_archive(
    name = "build_bazel_rules_nodejs",
    sha256 = "d0c4bb8b902c1658f42eb5563809c70a06e46015d64057d25560b0eb4bdc9007",
    urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/1.5.0/rules_nodejs-1.5.0.tar.gz"],
)
  

Activity

  1. alexeagle commented on Apr 1, 2020

    @alexeagle
    Collaborator

    js_library has a built-in copy_to_bin action on InputArtifacts so you get relative imports together again. That's how @gregmagolan solved this in the linker PR.

  2. changed the title [-]ts_project emited files unable to resolve files not in bazel-out[/-] [+]document convenient way to lay out all files in bazel-out[/+] on Apr 1, 2020
  3. alexeagle commented on Apr 1, 2020

    @alexeagle
    Collaborator

    certainly not a ts_project bug, it's doing the right thing with its inputs and outputs.
    The question is how the user should express that they want other sources of the bundler to be copied to the output tree. You could manually add copy_to_bin rules for it, but maybe we should make the js_library rule part of the public API, as it now does this https://github.com/bazelbuild/rules_nodejs/blob/1.5.0/internal/js_library/js_library.bzl#L57-L63

  4. alexeagle commented on Apr 24, 2020

    @alexeagle
    Collaborator

    I'm doing some work right now with cra/react-scripts and copy_to_bin works pretty well, just use it as a drop-in replacement for filegroup and you get a self-contained output directory

  5. alexeagle commented on Jun 9, 2020

    @alexeagle
    Collaborator

    We should add a bit of docs somewhere for 2.0 to explain the current situation.
    IF js_library becomes public API then it changes what we tell you to do...

  6. added this to the 2.0 milestone on Jun 9, 2020
  7. alexeagle commented on Jun 18, 2020

    @alexeagle
    Collaborator

    js_library not going public in time for 2.0, so I think this should slip too.

  8. removed this from the 2.0 milestone on Jun 18, 2020
  9. alexeagle commented on Sep 10, 2020

    @alexeagle
    Collaborator

    Documenting this now in the js_library rule

  10. added 3 commits that reference this issue on Sep 10, 2020
    a9e580c
    72e5ad4
    a4fb119
  11. added a commit that references this issue on Jan 15, 2021
    9671291
  12. added a commit that references this issue on Nov 5, 2025
    1e357fd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions