-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
foo.ts is resolved before foo.d.ts even if the latter is in files[] #22208
Comments
By the way, the previous compilation produced a readonly |
the rootDirs resolution logic gives precedence to closest directory. the rational is that these rootDirs are meant to "augment" and not "overwrite" the contents of local files. this saves us from looking that said. i would like to get more context on what you are trying to achieve. this seems similar to the Project to project reference @RyanCavanaugh is working on. |
Just trying to compile parts of an application independently, the same thing we've been doing at Google from the beginning. But as I mentioned, we've worked around this problem with bazel sandboxing and our custom compiler. Now I want to use Yes, the Bazel approach is a precursor to TS natively understanding multiple compilation units, I'd be happy to discuss that! In the meantime I still haven't found a workaround for this issue... |
My attempt at restating Alex's problem: given that compilation already happened for his 'lib' thinger, his tsconfig explicitly lists a |
When building outside the Bazel sandbox (in particular, on Windows where the sandbox is not available), vanilla tsc doesn't support multiple compilation units. See details in that TypeScript bug. The workaround is to build tsc_wrapped as a single compilation unit. PiperOrigin-RevId: 187475876
These are really two different phases. the first is identifing what files belong to the compilation unit by looking at imports. this lists all files. which includes |
As i said earlier, the alternative is to go through sourceDirs as they are listed, but that means that for the common case, we will be touching the disk many times for files that do not exist. this optimization of finding the shortest path allows us to lookup files in the same folder as they were referenced before trying other rootDirs. |
I think the way to fix this is not to always try to resolve imports using other rootDirs, only to check if the rootFiles already satisfy an import. |
Alternative idea: when |
As indicated in this comment, we need to allow TS to read files like node_modules/foo/package.json, and this cannot be included in the files[] list in tsconfig, so we still cannot restrict fileExists to only files in the cache. Ultimately as Martin points out this is the correct behavior. This fix is needed in Angular, where we compile rxjs in an aspect to get the "ESM5" JavaScript flavor, and this suffers from microsoft/TypeScript#22208 where we try to read a `.ts` file when the `.d.ts` file was in the root files. In this case we don't have a worker mode so the usual sandboxing doesn't mask the problem. PiperOrigin-RevId: 194095485
@RyanCavanaugh just to confirm on the "help wanted" and "committed" tags that is fixing it the way #22208 (comment) is proposing? |
Here's a reproduction of the issue. |
When building outside the Bazel sandbox (in particular, on Windows where the sandbox is not available), vanilla tsc doesn't support multiple compilation units. See details in that TypeScript bug. The workaround is to build tsc_wrapped as a single compilation unit. PiperOrigin-RevId: 187475876
As indicated in this comment, we need to allow TS to read files like node_modules/foo/package.json, and this cannot be included in the files[] list in tsconfig, so we still cannot restrict fileExists to only files in the cache. Ultimately as Martin points out this is the correct behavior. This fix is needed in Angular, where we compile rxjs in an aspect to get the "ESM5" JavaScript flavor, and this suffers from microsoft/TypeScript#22208 where we try to read a `.ts` file when the `.d.ts` file was in the root files. In this case we don't have a worker mode so the usual sandboxing doesn't mask the problem. PiperOrigin-RevId: 194095485
When building outside the Bazel sandbox (in particular, on Windows where the sandbox is not available), vanilla tsc doesn't support multiple compilation units. See details in that TypeScript bug. The workaround is to build tsc_wrapped as a single compilation unit. PiperOrigin-RevId: 187475876
As indicated in this comment, we need to allow TS to read files like node_modules/foo/package.json, and this cannot be included in the files[] list in tsconfig, so we still cannot restrict fileExists to only files in the cache. Ultimately as Martin points out this is the correct behavior. This fix is needed in Angular, where we compile rxjs in an aspect to get the "ESM5" JavaScript flavor, and this suffers from microsoft/TypeScript#22208 where we try to read a `.ts` file when the `.d.ts` file was in the root files. In this case we don't have a worker mode so the usual sandboxing doesn't mask the problem. PiperOrigin-RevId: 194095485
Affects at least TS 2.7.2 and 2.6.2. This problem appears when compiling files separately, like we do under Bazel.
Imagine this simple app
src/lib.ts
src/main.ts
Imagine
lib.ts
was compiled separately, so there already existsdist/lib.d.ts
Now, I want to compile
main.ts
as a separate program. Givensrc/tsconfig.json
We see that
lib.d.ts
is already in the program before resolution begins. However the compiler resolves the import statement to thelib.ts
file instead, adding it to the program, and tries to emit on top of an input, so the error isOkay, we didn't want
lib.ts
in the program, so we should just use--noResolve
to prevent that, but it's also broken:So far our workaround at Google is one of:
However under Bazel we sometimes cannot sandbox (eg. on Windows) and cannot use our custom compiler (eg. when we are compiling it)
so we are stuck.
I found that
ts.CompilerOptions.suppressOutputPathCheck
could be a workaround, buttsc
doesn't allow that flag from the command line or tsconfig.json (it's not inoptionDeclarations
incommandLineParser.ts
)The text was updated successfully, but these errors were encountered: