aspect-build / rules_ts

Bazel rules for the `tsc` compiler from http://typescriptlang.org
https://docs.aspect.build/rules/aspect_rules_ts
Apache License 2.0
104 stars 58 forks source link

[Bug]: typescript 5.5.2 cannot find input files with source tsconfig.json #644

Open gzm0 opened 3 months ago

gzm0 commented 3 months ago

What happened?

Minimal reproducible example below.

With TS 5.5.2, sources cannot be found:

bazel build //...
INFO: Analyzed target //:test (91 packages loaded, 2863 targets configured).
WARNING: /home/tos/.cache/bazel/_bazel_tos/287294dcdaea82c1370bff9bd5064654/external/aspect_rules_ts~~ext~npm_typescript/BUILD.bazel:32:17: input 'package' of @@aspect_rules_ts~~ext~npm_typescript//:.aspect_rules_js/node_modules/typescript is a directory; dependency checking of directories is unsound
ERROR: /home/tos/dh/personal/hack/tsc/BUILD.bazel:3:11: Transpiling TypeScript project @@//:test [tsc -p tsconfig.json] failed: (Exit 2): tsc.sh failed: error executing TsProject command (from target //:test) bazel-out/k8-opt-exec-ST-d57f47055a04/bin/external/aspect_rules_ts~~ext~npm_typescript/tsc.sh --skipLibCheck --project tsconfig.json --outDir . --rootDir .

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
error TS18003: No inputs were found in config file '/home/tos/.cache/bazel/_bazel_tos/287294dcdaea82c1370bff9bd5064654/sandbox/linux-sandbox/984/execroot/_main/bazel-out/k8-fastbuild/bin/tsconfig.json'. Specified 'include' paths were '["**/*"]' and 'exclude' paths were '["/home/tos/.cache/bazel/_bazel_tos/287294dcdaea82c1370bff9bd5064654/sandbox/linux-sandbox/984/execroot/_main/bazel-out/k8-fastbuild/bin"]'.
Target //:test failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 1.016s, Critical Path: 0.30s
INFO: 4 processes: 3 internal, 1 local.
ERROR: Build did NOT complete successfully

When downgrading to 5.4.5:

bazel build //...
INFO: Analyzed target //:test (90 packages loaded, 2863 targets configured).
WARNING: /home/tos/.cache/bazel/_bazel_tos/287294dcdaea82c1370bff9bd5064654/external/aspect_rules_ts~~ext~npm_typescript/BUILD.bazel:32:17: input 'package' of @@aspect_rules_ts~~ext~npm_typescript//:.aspect_rules_js/node_modules/typescript is a directory; dependency checking of directories is unsound
INFO: Found 1 target...
Target //:test up-to-date:
  bazel-bin/test.js
INFO: Elapsed time: 0.931s, Critical Path: 0.14s
INFO: 2 processes: 1 internal, 1 local.
INFO: Build completed successfully, 2 total actions

Version

Development (host) and target OS/architectures:

Output of bazel --version:

bazel --version
bazel 7.2.1

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

bazel_dep(name = "aspect_rules_ts", version = "2.4.2")

rules_ts_ext = use_extension("@aspect_rules_ts//ts:extensions.bzl", "ext", dev_dependency = True)

rules_ts_ext.deps(
    # TS 5.5.2, broken:
    ts_version="5.5.2",
    ts_integrity="sha512-NcRtPEOsPFFWjobJEtfihkLCZCXZt/os3zf8nTxjVH3RvTSxjrCamJpbExGvYOF+tFHc3pA65qpdwPbzjohhew=="
    # TS 5.4.5, works:
    #ts_version="5.4.5",
    #ts_integrity="sha512-vcI4UpRgg81oIRUFwR0WSIHKt11nJ7SAVlYNIu+QpqeyXP+gpQJy/Z4+F0aGxSE4MqwjyXvW/TzgkLAx2AGHwQ=="
)

use_repo(rules_ts_ext, "npm_typescript")

Language(s) and/or frameworks involved:

None

How to reproduce

MODULE.bazel from above.

BUILD.bazel:

load("@aspect_rules_ts//ts:defs.bzl", "ts_project")

ts_project(
    name = "test",
    srcs = ["test.ts"],
)

tsconfig.json

{}

.bazelrc

common --@aspect_rules_ts//ts:skipLibCheck=always
common --@aspect_rules_ts//ts:default_to_tsc_transpiler

test.ts

console.log("foo");

Then run bazel build //:test

Any other information?

The tsconfig.json must be a source file.

If you do (and optionally delete tsconfig.json), the issue vanishes.

 ts_project(
     name = "test",
     srcs = ["test.ts"],
+    tsconfig = {},
 )
gzm0 commented 3 months ago

Further investigation shows that the difference between a source tsconfig.json and a generated tsconfig.json is the files parameter. If I add it to tsconfig.json ({ "files": ["test.ts"] }), everything compiles again.

gzm0 commented 3 months ago

My gut tells me that https://github.com/microsoft/TypeScript/pull/58042 could have changed how relative paths with symlinks are resolved but I cannot find any evidence of that.

I'm currently double-checking that I cannot reproduce this issue without rules_ts.

gzm0 commented 3 months ago

I have double checked that when running bare typescript (npx tsc), the error does not occur.

gzm0 commented 3 months ago

Specifying exclude: [] fixes the issue. It looks like typescript 5.5 adds the outDir passed via command line to exclude.

typescript 5.4 doesn't do that as can be shown experimentally (by setting a bogus include pattern):

TS 5.4:

error TS18003: No inputs were found in config file '/home/tos/.cache/bazel/_bazel_tos/287294dcdaea82c1370bff9bd5064654/sandbox/linux-sandbox/1051/execroot/_main/bazel-out/k8-fastbuild/bin/src/tsconfig.json'. Specified 'include' paths were '["**/*.tsx"]' and 'exclude' paths were '[]'.

TS 5.5 (note the differently reported exclude pattern):

error TS18003: No inputs were found in config file '/home/tos/.cache/bazel/_bazel_tos/287294dcdaea82c1370bff9bd5064654/sandbox/linux-sandbox/1054/execroot/_main/bazel-out/k8-fastbuild/bin/src/tsconfig.json'. Specified 'include' paths were '["**/*.tsx"]' and 'exclude' paths were '["/home/tos/.cache/bazel/_bazel_tos/287294dcdaea82c1370bff9bd5064654/sandbox/linux-sandbox/1054/execroot/_main/bazel-out/k8-fastbuild/bin/src"]'.

So a workaround is to override exclude manually.

alexeagle commented 3 months ago

I filed this upstream: https://github.com/microsoft/TypeScript/issues/59036

gzm0 commented 3 months ago

TY @alexeagle. Please LMK if there is anything I can help.

For discoverability:

workaround

add exclude: [] to your tsconfig.json.

alexeagle commented 3 months ago

I'll adopt that workaround to land the new version mirroring: https://github.com/aspect-build/rules_ts/pull/643

We'll see if there's progress from TS team, if not then I'll have to detect the error message and print the workaround :(

alexeagle commented 3 months ago

It's so gross :( :( https://github.com/aspect-build/rules_ts/pull/646/files