Typescript错误TS5055将JS文件导入TS
我想在同一项目中混合.js和.ts文件,但是我想修复一个错误(TS5055),尽管输出很好,但在用TSC编译项目时会出现。
这是一个tsconfig.json
{
"compilerOptions": {
"target": "es2022",
"module": "ES2022",
"allowJs": true,
"lib": [
"es2022",
"DOM"
],
"removeComments": true
},
"files": [
"./index.ts"
]
}
,这是示例ts文件:
import { lib } from "./lib/impotr.js"
console.log(["imported", lib.hello("friend")]);
打字稿编译器给出此错误:
PS D:\WHY> tsc -p .
error TS5055: Cannot write file 'D:/WHY/lib/impotr.js' \
because it would overwrite input file.
如何在tsconfig中修复它?
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.
here is a tsconfig.json
{
"compilerOptions": {
"target": "es2022",
"module": "ES2022",
"allowJs": true,
"lib": [
"es2022",
"DOM"
],
"removeComments": true
},
"files": [
"./index.ts"
]
}
and here is example ts file:
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来您没有指定
Outdir
。看看 this :
如果此之后仍然存在错误,建议将
allowjs
设置为false
It seems you didn't specify an
outDir
.Take a look at this:
If the error is still present after this, it is recommended to set
allowJs
tofalse