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

File is not being compiled while other files in the same directory ARE compiled #44845

Closed
BTOdell opened this issue Jul 1, 2021 · 6 comments
Closed
Labels
Needs Investigation This issue needs a team member to investigate its status. Rescheduled This issue was previously scheduled to an earlier milestone

Comments

@BTOdell
Copy link

BTOdell commented Jul 1, 2021

Bug Report

The TypeScript compiler will not compile any new files that I add to my src directory, but three older/existing files are compiled fine.

See the GitHub repo below for context.

Under packages/core/src there are 4 .ts files and two tsconfig files. The tsconfig.json file builds the directory to ES modules and the tsconfig.cjs.json file builds the directory to CommonJS modules. After running npm install, you can run npm run compile from the root of the Git repository and it will use project references to build all of the packages in the monorepo. After compiling, the dist directory next to the src directory SHOULD contain transpiled .js files for all 4 input .ts files. But for some reason, the BufferUtils.ts file is left out and not compiled. However, BufferUtils IS compiled successfully in CommonJS mode and put in the cjs directory (next to the src directory). And, better yet, the TypeScript compiler does not output a single error, just silently fails to output a .js file for BufferUtils.

I have tried:

  • Renaming the file (from BufferUtils.ts to BufferUtil.ts)
  • Creating a new file named aaa.ts to see if that file would be compiled, and it WASN'T!

My tsconfig.json files do not contain any "files", "include", or "exclude" directives. My monorepo uses a "solution"-based structure where the location of files relative to tsconfig.json files defines the build scoping. As far as I know, my configuration files are perfectly valid.

🔎 Search Terms

label:bug file not compile

🕗 Version & Regression Information

4.3.5
Also, tried nightly version 4.4.0-dev.20210701

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about compiler behavior.
  • I was unable to test this on prior versions because my project relies on the newly added "override" keyword.

Playground Link GitHub repo

GitHub repo

🙁 Actual behavior

Some files are being compiled, some aren't - all in the same directory with the same tsconfig.json

🙂 Expected behavior

All files in the directory should be compiled.

@BTOdell BTOdell changed the title File is not being compiled while other files in the same directory ARE compiled. File is not being compiled while other files in the same directory ARE compiled Jul 1, 2021
@BTOdell
Copy link
Author

BTOdell commented Jul 1, 2021

It seems like the issue is related to project references.
If tsconfig.json references tsconfig.cjs.json (so tsconfig.cjs.json is built first), and tsconfig.cjs.json builds file A, then tsconfig.json will avoid building the same file - even if it means the source file will be built to two separate output directories.

What is strange is why did this work for the first three files? Or, specifically the files named "Box", "BoxEncoding", and "core"?
I tried swapping the code contents of BufferUtils.ts with Box.ts, and the BufferUtils.ts file still wouldn't compile, so it has nothing to do with the content of the files.

I came up with a workaround by renaming tsconfig.json to tsconfig.esm.json, and then creating a new tsconfig.json that references BOTH tsconfig.esm.json and tsconfig.cjs.json. I also removed the reference from tsconfig.esm.json to tsconfig.cjs.json so there wouldn't (or shouldn't) be any sharing of input files - and it worked! All files were compiled successfully.

I still think this is a bug in the project references implementation in how it avoids performing duplicate compilation. I assume somewhere in the code, there is a Set of resolved input file paths so that it can remember if it's already compiled a file. In addition to the input file path, it should also consider the output path in the Set key.

@sandersn sandersn added the Needs Investigation This issue needs a team member to investigate its status. label Jul 1, 2021
@sandersn sandersn added this to the TypeScript 4.4.1 (RC) milestone Jul 1, 2021
@andrewbranch andrewbranch added the Rescheduled This issue was previously scheduled to an earlier milestone label Aug 30, 2021
@alexmorleyfinch
Copy link

Me and my team ran into this issue. I don't have time to prepare a full bug report, but I will provide as much detail as possible to help this issue along.

We were using project references, and were exporting 4 files in one of the referenced projects. One of the files was an index.js that exported the other 3 files.

We experienced strange behaviour: when the referenced project was built, all 4 files appeared in the local dist (which was the outDir). However when the parent tsconfig project was built, there was a file missing in the build output. In other words, it worked in the dist folder closest to the project, but the top-level dist was missing a file.

We learned that if we removed the export from the index.js for the missing file, suddenly it appeared in the top-level dist. Strange?? If we removed the index.js completely, it also worked.

We then learned that if we add the index.js back, any file interpreted after the index.js was failing... So if we called the file utils.js, it would get missed. If we called it Utils.ts, it would work. If we called it foo.ts it would work. If we called it response.ts it would fail.

It appeared that the naming/casing of the file heavily influenced whether it would appear in the final dist or not. It also appeared to be sorted by ASCII so, anything starting with an upper case would work, and any files that started with a lower case but came before i (for index.js) would work. However any files starting with a lower case after the letter "i" had failed.

That is all the info I can provide. If I get time I'll get a reproducible repo set up

@RizqiSyahrendra
Copy link

I've also experienced similar problem, now I have no idea what to do

@RizqiSyahrendra
Copy link

I've also experienced similar problem, now I have no idea what to do

Solved, just tsconfig.json problem

@elibarzilay elibarzilay removed their assignment Sep 29, 2023
@RyanCavanaugh
Copy link
Member

Please log a new issue with a concrete repro if possible. Thanks!

@TimUnderhay
Copy link

@RyanCavanaugh FYI I've opened #58156 which I believe reproduces this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Investigation This issue needs a team member to investigate its status. Rescheduled This issue was previously scheduled to an earlier milestone
Projects
None yet
Development

No branches or pull requests

8 participants