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?
It seems you didn't specify an 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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.