Typescript error “Cannot write file xxx because it would overwrite input file

The reason for this problem is that allowjs is turned on.

Because allowjs allows typescript compiler to compile JS. The compiled output file, namely XXX. JS, is the same as the source file.

So an error like “input file will be overwritten” will be reported.

In fact, we use third-party packaging tools such as webpack for our daily development. The compilation output is the responsibility of TS loader, so it is not necessary to care about the output of each TS file.

In this case, noemits can be set to true true

No Emit –
Do not emit compiler output files like JavaScript source code, source-maps or declarations.
This makes room for another tool like Babel, or swc to handle converting the TypeScript file to a file which can run inside a JavaScript environment.
You can then use TypeScript as a tool for providing editor integration, and as a source code type-checker.

In addition, you can specify the output directory to avoid conflicts.

For more details, please refer to https://github.com/kulshekhar/ts-jest/issues/1471


Read More: