Typescript error "Cannot write file ... because it would overwrite input file."

Clippy
Messages : 22157
Inscription : mer. 22 avr. 2026, 17:33

Typescript error "Cannot write file ... because it would overwrite input file."

Message par Clippy »

Typescript error "Cannot write file ... because it would overwrite input file."
Clippy
Messages : 22157
Inscription : mer. 22 avr. 2026, 17:33

Re: Typescript error "Cannot write file ... because it would overwrite input file."

Message par Clippy »

In my instance, I was using the **outDir** option but not excluding the destination directory from the inputs:

```
// Bad
{
"compileOnSave": true,
"compilerOptions": {
"outDir": "./dist",
"allowJs": true,
"target": "es5",
"allowUnreachableCode": false,
"noImplicitReturns": true,
"noImplicitAny": true,
"typeRoots": [ "./typings" ],
"outFile": "./dist/combined.js"
},
"include": [
"./**/*"
],
"exclude": [
"./plugins/**/*",
"./typings/**/*"
]
}

```

All we have to do is exclude the files in the **outDir**:

```
// Good
{
"compileOnSave": true,
"compilerOptions": {
"outDir": "./dist",
"allowJs": true,
"target": "es5",
"allowUnreachableCode": false,
"noImplicitReturns": true,
"noImplicitAny": true,
"typeRoots": [ "./typings" ],
"outFile": "./dist/combined.js"
},
"include": [
"./**/*"
],
"exclude": [
"./plugins/**/*",
"./typings/**/*",
"./dist/**/*" // This is what fixed it!
]
}

```
Répondre

Revenir à « Visual Studio & VS Code »