rules_nodejs
rules_nodejs copied to clipboard
TS18003 with ts_project consisting only of generated files
🐞 bug report
Affected Rule
The issue is caused by the rule: ts_project
Is this a regression?
Unknown
Description
When building a ts_project rule where the srcs consist entirely of files generated with genrule, the tsc command run by Bazel produces the error "error TS18003: No inputs were found in config file...".
🔬 Minimal Reproduction
https://github.com/jfirebaugh/bazel_test/commit/d116a9f38ba6338f6e31a33c24d52088632051e4
🔥 Exception or Error
$ bazel build //b/...
INFO: Invocation ID: 8ec6e305-ab80-4efd-8acb-a5048548b0a5
INFO: Build option --define has changed, discarding analysis cache.
INFO: Analyzed 3 targets (0 packages loaded, 874 targets configured).
INFO: Found 3 targets...
ERROR: /Users/john/figma/bazel_repro/bazel_test/a/BUILD.bazel:9:11: Compiling TypeScript project //a:a [tsc -p a/tsconfig.json] failed: (Exit 2): tsc.sh failed: error executing command bazel-out/host/bin/external/npm/typescript/bin/tsc.sh --project a/tsconfig.json --outDir bazel-out/darwin-fastbuild/bin/a --rootDir bazel-out/darwin-fastbuild/bin/a --declarationDir ... (remaining 4 argument(s) skipped)
Use --sandbox_debug to see verbose messages from the sandbox
error TS18003: No inputs were found in config file '/private/var/tmp/_bazel_johnfirebaugh/3aa0600423f41b54a36b0cd08d44e491/sandbox/darwin-sandbox/28/execroot/bazel_test/a/tsconfig.json'. Specified 'include' paths were '["**/*"]' and 'exclude' paths were '[]'.
🌍 Your Environment
Operating System:
macOS 11.4
Output of bazel version:
Build label: 4.2.1-homebrew
Build target: bazel-out/darwin-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Tue Jan 1 00:00:00 1980 (315532800)
Build timestamp: 315532800
Build timestamp as int: 315532800
Rules_nodejs version:
(Please check that you have matching versions between WORKSPACE file and @bazel/* npm packages.)
4.2.0
Anything else relevant?
I'm basing the minimal reproduction on https://github.com/bazelbuild/rules_nodejs/issues/2967#issuecomment-926885695 and https://github.com/bazelbuild/rules_nodejs/blob/c0a8b3688e96f2ae9c05b58e277ccced890b281d/packages/typescript/test/generated_ts/BUILD.bazel.
The latter uses ts_library, and I've gotten it to work using ts_library, but the documentation states that ts_library should not be used for new code so I'm trying to avoid it.
I think you need to include the lines about ../../../blaze-bin etc in your tsconfig so typescript can resolve files built in multiple places
Sorry, I'm not sure what "lines about ../../../blaze-bin etc" refers to. Is there a link where I can read about that?
Sorry I was typing from my phone. See: https://bazelbuild.github.io/rules_nodejs/TypeScript.html#ts_project-1
Thanks for the pointer. I don't think that's the issue here. I've added a rootDirs section. Bazel/tsc output is unchanged: https://github.com/jfirebaugh/bazel_test/commit/42acea57293d87022b4eb91573183ede2bc6e66b
I some digging with -s and --sandbox_debug. The default for include is ["**/*"], which is resolved relative to the location of tsconfig.json, which winds up being a directory in the sandbox.
With non-generated srcs, this sandbox directory also contains symlinks to the sources.
With generated srcs, the sandbox directory contains only the symlink to tsconfig.json.
There's also a difference in the --rootDir option passed to tsc, but this doesn't help, because per docs, --rootDir does not affect which files become part of the compilation.
+1 to this issue. I've been looking at generating typescript definitions from a protobuf spec, but I am getting a similar error when I try to compile the generated ts code
One way to resolve this is with a dict-typed tsconfig attribute to ts_project - in this case a tsconfig file is generated, so that it lives in the bazel-out tree. That would be next to your generated .ts files, and also when we generate the tsconfig file we explicitly add files entries to it.
Another way to debug this with tsc is the --listFiles argument, like args = ["--listFiles"] - then TypeScript prints whatever files it adds to the ts.Program.
This issue has been automatically marked as stale because it has not had any activity for 6 months. It will be closed if no further activity occurs in 30 days. Collaborators can add a "cleanup" or "need: discussion" label to keep it open indefinitely. Thanks for your contributions to rules_nodejs!
Still relevant.
The only way for this to work in rules_nodejs is to have the tsconfig file in the output tree. You could pass a dictionary to the ts_project#tsconfig attribute to have one generated, or use copy_to_bin (https://docs.aspect.build/aspect-build/bazel-lib/v0.9.6/docs/copy_to_bin-docgen.html#copy_to_bin or the one in rules_nodejs) to copy your source tsconfig into the output folder.
Note that in rules_js we decided that all inputs have to live in the output tree to make this and other JS problems easily solved, as many tools are like tsc and assume there's a single tree containing inputs, outputs, and node_modules.
This issue has been automatically marked as stale because it has not had any activity for 6 months. It will be closed if no further activity occurs in 30 days. Collaborators can add a "cleanup" or "need: discussion" label to keep it open indefinitely. Thanks for your contributions to rules_nodejs!
Closing since rules_ts fixes this, and this repo is no longer maintained.