Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeScript errors in VSCode: "Cannot write file 'x' because it would overwrite input file."

I'm using TypeScript in VSCode to raise the bar on my JavaScript quality. However, tsconfig.json keeps throwing errors that it cannot write my .js files. Specifically:

"Cannot write file 'lib/chart.js' because it would overwrite input file."

I've seen several similar questions here, but they all simply suggest to exclude the .js files. However, I actually want TypeScript to show me code warnings for those files.

I'm looking for suggestions on how to have TypeScript review my JS files, but not keep throwing errors about not being able to write the input file itself.

Note, that this doesn't happen for all my .js files, just some of them.

Below is my tsconfig.json file. Note that all my .js files are in the lib folder.

{
    "compilerOptions": {
        "allowJs": true,
        "checkJs": true,
        "lib": ["es2018", "dom"]
    },
    "include": [
        "lib"
    ],
    "typeAcquisition": {
        "enable": true
    }
}
like image 898
Odin Anderson Avatar asked Aug 28 '26 17:08

Odin Anderson


1 Answers

Cannot write file 'lib/chart.js' because it would overwrite input file."

Use outDir if you are using allowJs. TypeScript will take the input .js files and put a same named one in the outDir.

like image 100
basarat Avatar answered Aug 31 '26 05:08

basarat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!