rules_nodejs
rules_nodejs copied to clipboard
Can't build certain ts_project targets on Windows, errors with "XXX is not under 'rootDir' 'YYY'. 'rootDir' is expected to contain all source files."
🐞 bug report
Affected Rule
The issue is caused by the rule:ts_project
I have found I hit a brick wall every time I migrate our codebase from ts_library to ts_project. As an example I pulled down @jbedard's
https://github.com/bazelbuild/rules_nodejs/pull/2209
which endeavours to migrate examples/angular to ts_project, and ran
bazel build //src/app --enable_runfiles=true
in examples/angular
On Windows 10 it fails with:
C:\Users\Matt\Documents\GitHub\rules_nodejs_tsp\rules_nodejs\examples\angular>bazel build //src/app --enable_runfiles=true
INFO: Invocation ID: 7697f5ab-6edd-45ee-bfe1-db07c0e5ed11
WARNING: C:/users/matt/documents/github/rules_nodejs_tsp/rules_nodejs/examples/angular/src/BUILD.bazel:261:12: target 'pwa' is both a rule and a file; please choose another name for the rule
INFO: Analyzed target //src/app:app (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
ERROR: C:/users/matt/documents/github/rules_nodejs_tsp/rules_nodejs/examples/angular/src/app/home/BUILD.bazel:5:14: Compiling TypeScript project //src/app/home:home [tsc -p src/tsconfig.json] failed: (Exit 1): ngc.bat failed: error executing command bazel-out/host/bin/external/npm/@angular/compiler-cli/bin/ngc.bat --project src/tsconfig.json --outDir bazel-out/x64_windows-fastbuild/bin/src/app/home --rootDir src/app/home --declarationDir ... (remaining 2 argument(s) skipped)
error TS6059: File 'C:/users/matt/_bazel_matt/u3fem6ok/execroot/examples_angular/src/app/hello-world/hello-world.component.spec.ts' is not under 'rootDir' 'src/app/home'. 'rootDir' is expected to contain all source files.
error TS6059: File 'C:/users/matt/_bazel_matt/u3fem6ok/execroot/examples_angular/src/initialize_testbed.ts' is not under 'rootDir' 'src/app/home'. 'rootDir' is expected to contain all source files.
error TS6059: File 'C:/users/matt/_bazel_matt/u3fem6ok/execroot/examples_angular/src/lib/shorten/index.ts' is not under 'rootDir' 'src/app/home'. 'rootDir' is expected to contain all source files.
error TS6059: File 'C:/users/matt/_bazel_matt/u3fem6ok/execroot/examples_angular/src/main.dev.ts' is not under 'rootDir' 'src/app/home'. 'rootDir' is expected to contain all source files.
error TS6059: File 'C:/users/matt/_bazel_matt/u3fem6ok/execroot/examples_angular/src/main.prod.ts' is not under 'rootDir' 'src/app/home'. 'rootDir' is expected to contain all source files.
error TS6059: File 'C:/users/matt/_bazel_matt/u3fem6ok/execroot/examples_angular/src/main.ts' is not under 'rootDir' 'src/app/home'. 'rootDir' is expected to contain all source files.
error TS6059: File 'C:/users/matt/_bazel_matt/u3fem6ok/execroot/examples_angular/src/prerender-spec.ts' is not under 'rootDir' 'src/app/home'. 'rootDir' is expected to contain all source files.
error TS6059: File 'C:/users/matt/_bazel_matt/u3fem6ok/execroot/examples_angular/src/prerender.ts' is not under 'rootDir' 'src/app/home'. 'rootDir' is expected to contain all source files.
error TS6059: File 'C:/users/matt/_bazel_matt/u3fem6ok/execroot/examples_angular/src/server.ts' is not under 'rootDir' 'src/app/home'. 'rootDir' is expected to contain all source files.
Target //src/app:app failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 23.398s, Critical Path: 21.33s
INFO: 7 processes: 6 internal, 1 worker.
FAILED: Build did NOT complete successfully
In Ubuntu WSL, the same command completes successfully:
matt@LAPTOP-DH6V2O9C:~/rules_nodejs_tsp/rules_nodejs/examples/angular$ bazel
build //src/app
Starting local Bazel server and connecting to it...
INFO: Invocation ID: 6c04d8dc-1a05-4839-9525-1afe3faa6844
WARNING: /home/matt/rules_nodejs_tsp/rules_nodejs/examples/angular/src/BUILD.bazel:261:12: target 'pwa' is both a rule and a file; please choose another name for the rule
INFO: Analyzed target //src/app:app (169 packages loaded, 17329 targets configured).
INFO: Found 1 target...
WARNING: failed to create one or more convenience symlinks for prefix 'dist/':
cannot create symbolic link dist/bin -> /home/matt/.cache/bazel/_bazel_matt/bce7af6da99ec20d4a83fa8d48de82ec/execroot/examples_angular/bazel-out/k8-fastbuild/bin: /home/matt/rules_nodejs_tsp/rules_nodejs/examples/angular/dist/bin (File exists)
cannot create symbolic link dist/testlogs -> /home/matt/.cache/bazel/_bazel_matt/bce7af6da99ec20d4a83fa8d48de82ec/execroot/examples_angular/bazel-out/k8-fastbuild/testlogs: /home/matt/rules_nodejs_tsp/rules_nodejs/examples/angular/dist/testlogs (File exists)
cannot create symbolic link bazel-out -> /home/matt/.cache/bazel/_bazel_matt/bce7af6da99ec20d4a83fa8d48de82ec/execroot/examples_angular/bazel-out: /home/matt/rules_nodejs_tsp/rules_nodejs/examples/angular/bazel-out (File exists)
cannot create symbolic link dist/out -> /home/matt/.cache/bazel/_bazel_matt/bce7af6da99ec20d4a83fa8d48de82ec/execroot/examples_angular/bazel-out: /home/matt/rules_nodejs_tsp/rules_nodejs/examples/angular/dist/out (File exists)
cannot create symbolic link dist/angular -> /home/matt/.cache/bazel/_bazel_matt/bce7af6da99ec20d4a83fa8d48de82ec/execroot/examples_angular: /home/matt/rules_nodejs_tsp/rules_nodejs/examples/angular/dist/angular (File exists)
Target //src/app:app up-to-date:
/home/matt/.cache/bazel/_bazel_matt/bce7af6da99ec20d4a83fa8d48de82ec/execroot/examples_angular/bazel-out/k8-fastbuild/bin/src/app/app-routing.module.js
/home/matt/.cache/bazel/_bazel_matt/bce7af6da99ec20d4a83fa8d48de82ec/execroot/examples_angular/bazel-out/k8-fastbuild/bin/src/app/app.component.js
/home/matt/.cache/bazel/_bazel_matt/bce7af6da99ec20d4a83fa8d48de82ec/execroot/examples_angular/bazel-out/k8-fastbuild/bin/src/app/app.module.js
/home/matt/.cache/bazel/_bazel_matt/bce7af6da99ec20d4a83fa8d48de82ec/execroot/examples_angular/bazel-out/k8-fastbuild/bin/src/app/service-worker.service.js
INFO: Elapsed time: 506.786s, Critical Path: 111.27s
INFO: 55 processes: 2 remote cache hit, 39 internal, 14 processwrapper-sandbox.
INFO: Build completed successfully, 55 total actions
I don't know what the problem is here, but it is symptomatically identical to the errors I see migrating over real-world projects. I think it explains my confusion over what rootDirs needs to be set to, as my company is Windows-based. I have only seen this on ts_project targets that depend on other ts_project targets.
Operating System:
Windows 10
Output of bazel version:
Bazelisk version: v1.8.1
Build label: 4.1.0
Build target: bazel-out/x64_windows-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Fri May 21 11:17:01 2021 (1621595821)
Build timestamp: 1621595821
Build timestamp as int: 1621595821
Rules_nodejs version:
(Please check that you have matching versions between WORKSPACE file and @bazel/* npm packages.)
3.6.0
Anything else relevant?
This issue has been automatically marked as stale because it has not had any activity for 90 days. It will be closed if no further activity occurs in two weeks. Collaborators can add a "cleanup" or "need: discussion" label to keep it open indefinitely. Thanks for your contributions to rules_nodejs!
Still an issue, don't close.
I'm experiencing this as well.
I am experiencing this also.
Does rules_nodejs (with its examples, which exercise things pretty well) CI on Windows?
An example of the error:
ERROR: C:/users/circleci/project/5-full-stack/client/src/app/BUILD.bazel:5:14: Compiling TypeScript project //client/src/app:app [tsc -p client/src/tsconfig.json] failed: (Exit 1): ngc.bat failed: error executing command bazel-out/host/bin/external/npm/@angular/compiler-cli/bin/ngc.bat --project client/src/tsconfig.json --outDir bazel-out/x64_windows-fastbuild/bin/client/src/app --rootDir client/src/app ... (remaining 3 argument(s) skipped)
error TS6059: File 'C:/users/circleci/_bazel_circleci/5gubvemx/execroot/full_stack_suite/client/src/main.dev.ts' is not under 'rootDir' 'client/src/app'. 'rootDir' is expected to contain all source files.
The project details aren't important, though I might start tearing out complexity to get a minimal reproduction.
The error as stated by the typescript compiler appears to be true. The tsconfig is in the source tree at client/src/tsconfig.json, and the rootDir is relative to that, "." by default, so also in the source tree. But it is being asked to compile C:/users/circleci/_bazel_circleci/5gubvemx/execroot/full_stack_suite/client/src/main.dev.ts, which is not in the source tree at all, and thus not under the rootDir.
I wonder if there is a way to get it to translate that rootDir to the corresponding place in the execroot where things are happening.
Yes, we have windows CI, you can see what it runs on every commit to stable. A few tests are disabled on Windows, which is naughty tech debt.
Typically the problem is that typescript runs outside a sandbox on windows and picks up files it shouldn't. I usually have to add an includes in the tsconfig.json to prevent it doing that.
The examples work on Mac even with --spawn_strategy=local.
But if I run the same tsc/ngc commands executed by bazel (extracted via the --subcommands option) on Mac and on Windows I get the same rootDir errors. This means that the typescript examples cannot be built without using bazel, correct?
@gregmagolan has a fix https://github.com/aspect-build/TypeScript/releases/tag/v4.3.5_resolveFromOutDir using our upstream fix.
Basically it was always a missing feature in TS to resolve .d.ts files from the outDir rather than locate .ts sources and add them to the program. With that fix patched in, you don't get this error since TS won't find files outside the rootDir.
I've gotten the "not under rootDir" error on macOS when using --spawn_strategy=local. It's the same underlying issue -- tsc prefers the .ts file in the source dir to the .d.ts file in the outDir.
To make the examples work on Windows I replaced ngc with a script which copies the input files in a new folder (the "sandbox") and then calls ngc to compile the "sandbox". In this way tsc won't find .ts sources outside of the sandbox. Instead, it will find the .d.ts files in the bazel-bin directory (which I add in rootDirs).
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!
This issue was automatically closed because it went 30 days without any activity since it was labeled "Can Close?"