You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
TypeScript renames modules when imported incorrectly #4719
While working on a larger project I encountered a strange behaviour of the TypeScript compiler that broke my project and was quite difficult to figure out. I've fiddled around and was able to break down the problem to the following simple example.
Assume a simple TypeScript project with two modules moduleA.ts and moduleB.ts with the first one importing something from the second one but with an incorrect cased filename within the import statement like this:
moduleA.ts
import {myFunction} from "./ModuleB"
myFunction();
moduleB.ts
export function myFunction() {}
When compiling this project with the beta version of TypeScript 1.6 on NPM I receive these output files:
moduleA.js
ModuleB.js
The compiler does not complain about the misspelled "./ModuleB" but simply renames the output file of moduleB.ts to ModuleB.js. If you reverse the example (put contents of moduleA into moduleB.ts and vice versa, misstype ./ModuleA) the compiler will not change the case of the output file names.
As there is no error for importing unknown modules (as reported in #4561) this error becomes realy hard to solve, imagine somewhere else in the project importing moduleB but this time using the correct spelling. This will break the code.
moduleC.ts
import {myFunction} from "./moduleB"
myFunction();
Thank you for your fast response. I searched through the issues but these two didn't show up. Your description of how TypeScript resolves the output file names in the second issue was very interesting and perfectly explains my initial problem.
So the real problem arrises cause TypeScript aligns its case sensitiveness to the file system it is currently running on while the underlying require call of an import statement is case sensitive on all platforms.
yes. it has been a pain point, and usually will take a few hours to figure out the root cause. As mentioned in #3626, we should have a flag to make it an error.
#5275 introduces a flag forceConsistentCasingInFileNames - when it is set compiler will report an error if some file has multiple references with inconsistent casing inside the program
Activity
mhegazy commentedon Sep 10, 2015
Similar to the issue reported in #3626 and #2011. we need a compiler option to make these casing mismatches an error.
sebastian-lenz commentedon Sep 10, 2015
Thank you for your fast response. I searched through the issues but these two didn't show up. Your description of how TypeScript resolves the output file names in the second issue was very interesting and perfectly explains my initial problem.
So the real problem arrises cause TypeScript aligns its case sensitiveness to the file system it is currently running on while the underlying
requirecall of animportstatement is case sensitive on all platforms.mhegazy commentedon Sep 10, 2015
yes. it has been a pain point, and usually will take a few hours to figure out the root cause. As mentioned in #3626, we should have a flag to make it an error.
vladima commentedon Oct 27, 2015
#5275 introduces a flag
forceConsistentCasingInFileNames- when it is set compiler will report an error if some file has multiple references with inconsistent casing inside the programvladima commentedon Oct 27, 2015
fixed in e811fec
sebastian-lenz commentedon Oct 28, 2015
🎉