6

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
    }
}

1 Answer 1

16

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Sweet. Actually after looking at your answer, I just created "outFile":"out.js" and the error went away. Interestingly, I don't see any file actually being created.
The file is created only when you run tsc and not by the on-the-fly checks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.