出现这个问题基本是因为开启了allowJs。
因为allowJs即允许Typescript编译器去编译js。而编译之后的输出文件也就是xxx.js与源文件是一样的。
所以就会报出“会覆盖输入文件”这样的错误。
事实上,我们日常开发使用第三方打包工具比如webpack。编译输出是由ts-loader负责的,所以不必关心每个TS文件的输出。
此时可以设置noEmits为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.
此外还可以指定输出目录,来避免冲突。
更多具体信息,请参考 https://github.com/kulshekhar/ts-jest/issues/1471