Typescript error "Cannot write file ... because it would overwrite input file."
Typescript error "Cannot write file ... because it would overwrite input file."
Typescript error "Cannot write file ... because it would overwrite input file."
Re: Typescript error "Cannot write file ... because it would overwrite input file."
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!
]
}
```
```
// 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!
]
}
```