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]: Cannot include package.json (needed for resolution) in srcs when resolve_json_module = True #689

Open
Silic0nS0ldier opened this issue Sep 9, 2024 · 1 comment
Labels
bug Something isn't working more info needed More info needed to proceed further

Comments

@Silic0nS0ldier
Copy link

What happened?

The target resembles

ts_project(
    name = "ts_prod",
    srcs = glob([
        "src/**/*.ts",
    ]) + [
        # need the package.json so TS can resolve the type: "module"
        ":package.json",
    ],
    resolve_json_module = True,
    # ...
)

When the target is analysed the following error is raised

ERROR: Traceback (most recent call last):
        File "/___/___/BUILD.bazel", line 21, column 11, in <toplevel>
                ts_project(
        File "/___/bazel_output_root/a0311ccbc25922c56ee2769278435101/external/aspect_rules_ts~/ts/defs.bzl", line 378, column 20, in ts_project
                ts_project_rule(
Error in ts_project: rule 'ts_prod' has file 'package.json' as both an input and an output
ERROR: package contains errors: ___: Traceback (most recent call last):
        File "/___/___/BUILD.bazel", line 21, column 11, in <toplevel>
                ts_project(
        File "/___/bazel_output_root/a0311ccbc25922c56ee2769278435101/external/aspect_rules_ts~/ts/defs.bzl", line 378, column 20, in ts_project
                ts_project_rule(
Error in ts_project: rule 'ts_prod' has file 'package.json' as both an input and an output

This does not occur in Rules TS v2.2.0, and only occurs in conjunction with resolve_json_module = True.

Version

Development (host) and target OS/architectures:

Output of bazel --version: 7.3.0

Version of the Aspect rules, or other relevant rules from your
WORKSPACE or MODULE.bazel file: 3.1.0

Language(s) and/or frameworks involved: NA

How to reproduce

1. Define a target with `ts_project` that takes `package.json` as an explicit input and `resolve_json_module = True`.
2. Perform any action which results in analysis of the containing `BUILD` file.

Any other information?

resolve_json_module = True is not used to import file listed in srcs with this scenario, rather this is being used to retrieve package version information in a strictly typed manner.

import eslintPackageJson from 'eslint/package.json' with { type: 'json' };
@Silic0nS0ldier Silic0nS0ldier added the bug Something isn't working label Sep 9, 2024
@jbedard
Copy link
Member

jbedard commented Oct 7, 2024

My attempt to reproduce it at HEAD has failed. Can you checkout #711 and see if you can reproduce it at HEAD or confirm it's fixed?

@jbedard jbedard added the more info needed More info needed to proceed further label Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working more info needed More info needed to proceed further
Projects
None yet
Development

No branches or pull requests

2 participants