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

[Bug]: JSON data from ts_project not found at runtime #250

Closed
loudmouth opened this issue Nov 20, 2022 · 2 comments
Closed

[Bug]: JSON data from ts_project not found at runtime #250

loudmouth opened this issue Nov 20, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@loudmouth
Copy link

loudmouth commented Nov 20, 2022

What happened?

After discussion in the Bazel Slack in the #javascript channel, opening an issue here to track this apparent bug.

Given a a ts_project that resolves data as a "JSON module", when running a js_binary that depends on that ts_project, the JSON file is not found at runtime. The expected behavior is that the data would be included at runtime. It is also expected that the data be available at compile time since it may imported, not only by it's local package target, but by other ts_projects that depend on it.

Version

Development (host) and target OS/architectures:

Output of bazel --version: bazel 5.3.2

Version of the Aspect rules, or other relevant rules from your
WORKSPACE or MODULE.bazel file: rules_ts-1.0.0-rc6

Language(s) and/or frameworks involved: TypesScript, JavaScript

How to reproduce

A branch reproducing the issue can be found here: https://github.com/loudmouth/bazel-rules_js-poc/tree/ts_project-data

Just try to running bazel run //app/app-a:main and the output will be:

"Error: Cannot find module './data.json'"

├── BUILD.bazel
├── WORKSPACE
├── app
│   └── app-a
│       ├── BUILD.bazel
│       ├── index.ts
├── lib
│   ├── lib-a
│   │   ├── BUILD.bazel
│   │   ├── index.ts
│   ├── lib-data
│   │   ├── BUILD.bazel
│   │   ├── data.json
│   │   ├── index.ts

Any other information?

Linking to the Slack thread since there was already discussion as to (a) possible fix(es)

@loudmouth loudmouth added the bug Something isn't working label Nov 20, 2022
@gregmagolan gregmagolan moved this to 🔖 Ready in Open Source Feb 5, 2023
@gzm0
Copy link
Contributor

gzm0 commented Feb 13, 2023

I have been investigating this and it seems a similar issue happens with imported JS files (when allow_js = True).

I suspect they both have the same root cause (unverified at this point): ts_project seems to never declare input files as dependencies of its output. It seems to only ever declare new tsc outputs.

In other words, for each input it currently decides between the following two states:

  • Needs to be declared as an output.
  • Doesn't need to be declared as an output (nor a dependency)

IIUC we'd need to add the following state:

  • Doesn't need to be declared as an output but as a dependency.

IMO this can most easily be seen between the following two lines:

default_outputs = output_sources[:] if len(output_sources) else output_declarations[:]

transitive_sources = js_lib_helpers.gather_transitive_sources(output_sources, ctx.attr.srcs + [ctx.attr.tsconfig] + ctx.attr.deps)

==> all non-transitive JS sources must be default outputs.

This is blocking our migration to rules_ts, so I might spend some more time looking into this. Any pointers are appreciated.

@gzm0
Copy link
Contributor

gzm0 commented Feb 13, 2023

As a workaround: The json inputs can be added to the assets parameter (additionally) to make them available downstream.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

No branches or pull requests

4 participants