You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Error "Cannot write file ... because it would overwrite input file." #27436
Started getting this after upgrading from 3.0.3 to 3.1.1. Looks like the same problem as #14538
Using create-react-app Webpack 2 project with ts-loader 3.5.0. Still builds fine, but VS Code pops the tsconfig error. In our case, unlike most people in #14538, the file mentioned is one of our JS sources.
This is a TS/JS mixed project. Made no other changes other than upgrading TS to 3.1.1. No problems prior. Latest VS Code. Still builds fine otherwise.
Having to explicitly set one option like outDir to enable other option like resolveJsonModule is not (in my opinion) a nice solution. There are many scenarios where, you can't have or do not want to have different outDir. For example in NativeScript the outDir is exactly the same which is resulting in that resolveJsonModule to be unusable with the latest TypeScript version.
I thing that the options should be decoupled - we shouldn't have to mandatory set one option to have another in a working state. Not to mention that you can still set the outDir` to the very same folder and cause the very same bug to reappear (which is creating a third rule - do not set outDir as the project dir...)
I'm not 100% certain this is related, however I'm attempting to compile and deploy a NestJS app, and was getting this error on npm run build.
Looking into it (I'm new to npm, typescript, ionic, and nest), my guess is that build is trying to also compile my output directory, and therefore has an output-will-overwrite-input conflict.
I resolved this by editing tsconfig.build.json, and adding my build directory to the exclude list. In NestJS, the build dir appears to default to dist.
Reacted by Igor, Fontumi Team, alf5, Pasha Nemchenko, Chris Lance, Juan Pablo de la Torre, HansITChange, Ryan Gasparini, Denis, Artem Sydorenko and 26 more
Reacted by Elias Skogevall, Zhikai Xiong and Juan Feliz
Reacted by Elias Skogevall, Eugene Samonenko, Flowwwww, Alexey Zaitsev and Vinnie
Reacted by Ted Conn, Önder Ceylan, nicorobo, Puzyr Mykola, Elias Skogevall, Tenza Burabura, Eugene Samonenko, Elaine, Alexey Zaitsev and Bailey Pownell
Reacted by Elias Skogevall, Eugene Samonenko and Elaine
I resolved this by editing tsconfig.build.json, and adding my build directory to the exclude list. In NestJS, the build dir appears to default to dist.
Make sure you have assigned an include in addition to an exclude in the tsconfig.json.
Looking into it (I'm new to npm, typescript, ionic, and nest), my guess is that build is trying to also compile my output directory, and therefore has an output-will-overwrite-input conflict.
Try to run TypeScript compiler with --listFiles flag
npx tsc --listFiles
in case when list have many entries it can be narrowed with
The error occurs despite the fact that the files it is complaining about are clearly inside dist:
error TS5055: Cannot write file '/Users/leila/dev/wip/jest-fp-ts/dist/index.d.ts' because it would overwrite input file.
error TS5055: Cannot write file '/Users/leila/dev/wip/jest-fp-ts/dist/matchers/index.d.ts' because it would overwrite input file.
In my case I have imports set up where src/index.ts imports and re-exports from src/matchers/index.ts which in turn imports and re-exports from src/matchers/eitherMatchers/index.ts.
The first two files are the ones with the compilation errors. The third file is fine. Other .d.ts files are fine too. So it looks like it might be related to how the import / export tree is affecting compilation.
Ah... another important piece of the puzzle. I discovered I had a manually created global.d.ts file that was mistakenly importing from dist instead of from src...
Once I fixed that, the problem went away. So maybe not the same problem others are seeing - but one way to reproduce it...
If adding the output directory to the exclude option didn't help, then check your source directory - you might accidentally import something from output directory in your sources. It also results in the aforementioned error
This is because TypeScript defaults to parsing TS files to generate JS files that are placed in the same directory, which may have the potential to overwrite JS files.
So, if you configured "allowJs": true in the tsconfig.json file, you need to configure "outDir": "./dist", and "exclude”: ["./dist"].
This way TypeScript does not have an override when parsing TS files.
Activity
RyanCavanaugh commentedon Oct 1, 2018
We need a way to reproduce the issue.
lvpro commentedon Oct 2, 2018
Setting outDir in tsconfig removed the error in VS Code for me. In my case, I set it to /dev/shm.
NickIliev commentedon Jan 18, 2019
Having to explicitly set one option like
outDirto enable other option likeresolveJsonModuleis not (in my opinion) a nice solution. There are many scenarios where, you can't have or do not want to have differentoutDir. For example in NativeScript theoutDiris exactly the same which is resulting in thatresolveJsonModuleto be unusable with the latest TypeScript version.I thing that the options should be decoupled - we shouldn't have to mandatory set one option to have another in a working state. Not to mention that you can still set the outDir` to the very same folder and cause the very same bug to reappear (which is creating a third rule - do not set outDir as the project dir...)
memetican commentedon Apr 2, 2019
I'm not 100% certain this is related, however I'm attempting to compile and deploy a NestJS app, and was getting this error on
npm run build.Looking into it (I'm new to npm, typescript, ionic, and nest), my guess is that build is trying to also compile my output directory, and therefore has an output-will-overwrite-input conflict.
I resolved this by editing
tsconfig.build.json, and adding my build directory to theexcludelist. In NestJS, the build dir appears to default todist.rxgx commentedon Aug 15, 2019
Make sure you have assigned an
includein addition to anexcludein thetsconfig.json.mt0erfztxt commentedon Dec 9, 2019
Try to run TypeScript compiler with
--listFilesflagin case when list have many entries it can be narrowed with
npx tsc --listFiles | grep distpjercic commentedon Dec 13, 2019
"exclude": ["node_modules", "**/*.test.ts", "dist"]
🐛 building doesn't work
leilapearson commentedon May 8, 2020
Might be able to help you reproduce this issue...
It seems like some part of the compilation process isn't recognizing that it is inside an excluded directory.
I don't don't see the problem if I do this:
I do see the problem if I do this:
or this:
The error occurs despite the fact that the files it is complaining about are clearly inside
dist:In my case I have imports set up where
src/index.tsimports and re-exports fromsrc/matchers/index.tswhich in turn imports and re-exports fromsrc/matchers/eitherMatchers/index.ts.The first two files are the ones with the compilation errors. The third file is fine. Other
.d.tsfiles are fine too. So it looks like it might be related to how the import / export tree is affecting compilation.leilapearson commentedon May 8, 2020
Ah... another important piece of the puzzle. I discovered I had a manually created
global.d.tsfile that was mistakenly importing fromdistinstead of fromsrc...Once I fixed that, the problem went away. So maybe not the same problem others are seeing - but one way to reproduce it...
outrowender commentedon Sep 9, 2020
For me the problem was solved adding dist to exclude and
"compilerOptions"."allowJs": falseand"exclude": ["dist"]dbelarmino commentedon Sep 11, 2020
This worked for me
impssngr commentedon Dec 3, 2020
This might help anyone who ran into this issue:
If adding the output directory to the exclude option didn't help, then check your source directory - you might accidentally import something from output directory in your sources. It also results in the aforementioned error
RyanCavanaugh commentedon Dec 3, 2020
We haven't seen any instance of this that isn't a misconfiguration
#40011 should help in the future for diagnosing such problems
asins commentedon Sep 24, 2021
This is because TypeScript defaults to parsing TS files to generate JS files that are placed in the same directory, which may have the potential to overwrite JS files.
So, if you configured
"allowJs": truein thetsconfig.jsonfile, you need to configure"outDir": "./dist", and"exclude”: ["./dist"].This way TypeScript does not have an override when parsing TS files.
这是因为TypeScript默认在解析TS文件生成JS文件是放在相同目录中的,这就有可能存在覆盖JS文件的可能。
所以,如果你在
tsconfig.json文件中配置了"allowJs": true,那么就需要配置"outDir": "./dist",以及配置"exclude”: ["./dist"]。这样TypeScript在解析TS文件时才不会存在覆盖的情况。
Workaround to calm down the TS compiler when working with JS files (see