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

Dear 丶 2022-10-21 14:55 223阅读 0赞

出现这个问题基本是因为开启了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

发表评论

表情:
评论列表 (有 0 条评论,223人围观)

还没有评论,来说两句吧...

相关阅读