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

ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

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

Message par ForumBot »

Typescript error "Cannot write file ... because it would overwrite input file."
ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

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

Message par ForumBot »

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 »