[英]Typescript error TS5055 when importing js file into ts
I want to mix .js and .ts files in the same project, but there is an error (TS5055) that i want to fix, which appears when the project is compiled with tsc, although the output is fine.我想在同一个项目中混合 .js 和 .ts 文件,但是有一个我想修复的错误(TS5055),当项目使用 tsc 编译时出现,尽管输出很好。
here is a tsconfig.json这是一个 tsconfig.json
{
"compilerOptions": {
"target": "es2022",
"module": "ES2022",
"allowJs": true,
"lib": [
"es2022",
"DOM"
],
"removeComments": true
},
"files": [
"./index.ts"
]
}
and here is example ts file:这是示例 ts 文件:
import { lib } from "./lib/impotr.js"
console.log(["imported", lib.hello("friend")]);
typescript compiler gives this error:打字稿编译器给出了这个错误:
PS D:\WHY> tsc -p .
error TS5055: Cannot write file 'D:/WHY/lib/impotr.js' \
because it would overwrite input file.
How to fix it in tsconfig?如何在 tsconfig 中修复它?
It seems you didn't specify an outDir
.看来您没有指定
outDir
。 Take a look at this :看看这个:
{
"compilerOptions": {
"target": "es2022",
"module": "ES2022",
"allowJs": true,
"outDir": "build",
"lib": [
"es2022",
"DOM"
],
"removeComments": true
},
"files": [
"./index.ts"
]
}
If the error is still present after this, it is recommended to set allowJs
to false
如果在此之后错误仍然存在,建议将
allowJs
设置为false
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.