-
Notifications
You must be signed in to change notification settings - Fork 12.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error "Cannot write file ... because it would overwrite input file." #14538
Comments
I also get same problem. |
is |
Sorry, I cannot share the project, and no that flag is not set. My I have teammates complaining about the same issue happening to them on the same projects. I also work on a project at home on a different computer that has the exact same issue & the same setup (TS 2.2.1, VS2015 U3, etc.) |
do you see the same behavior if you create a bare-bones project with the same configurations? |
We have the same problem wc-catalogue/blaze-elements#299 although with type definitions write access |
@Hotell do you see this without "awesome-typescript-loader"? can you share repro steps with me? |
yup, as you can see in the issue the output is from running raw just clone the repo https://github.com/wc-catalogue/blaze-elements
|
We're having a similar issue -- same version of typescript (2.2.1) and Visual Studio 2015 (Update 3); the first time the build runs, there are zero errors, but after that we get hundreds of these errors. It appears that all of the errors (for us) are in the "node_modules" folder, which we have set to exclude in our tsconfig.json file. -- From looking at similar bugs, it seems like the excludes aren't treated the same in this version of typescript? Our tsconfig.json file:
Some of the errors we get (they're all the same, but different files):
Again, if we delete the "node_modules" folder the build will work once, but then once it's been recreated, it will fail on the next rebuild. |
@Hotell i am not seeing this locally, what am i missing? c:\test\14538\blaze-elements>yarn tsc
yarn tsc v0.18.1
$ "c:\test\14538\blaze-elements\node_modules\.bin\tsc"
Done in 5.46s.
c:\test\14538\blaze-elements>yarn tsc
yarn tsc v0.18.1
$ "c:\test\14538\blaze-elements\node_modules\.bin\tsc"
Done in 5.87s.
c:\test\14538\blaze-elements>dir /B definitions
packages
polyfills.d.ts
styles.d.ts
test-helpers.d.ts
vendors.d.ts
c:\test\14538\blaze-elements>yarn tsc
yarn tsc v0.18.1
$ "c:\test\14538\blaze-elements\node_modules\.bin\tsc"
Done in 4.48s. |
@BrainSlugs83 if you have a repro project i would love to take a look. |
is the tsconfig.json part of your project? and can you confirm the content type is "Content"? if so, can you share your project? |
@mhegazy Hi, yes I can confirm tsconfig.json is included in the project: But I am sorry I don't know what "content type" are you referring to, can you please clarify? I can't share the project. |
On my project, I can also confirm that the tsconfig file is included in the project file, and it is listed as content. |
@max-favilli I think @mhegazy means the "Build Action" when talking about "content type". Select tsconfig.json in the solution explorer. Bring up the Properties window (F4 key by default). There will be a Build Action property. |
Can you share your virtual project structure with me, to get that you need to:
|
@mhegazy like this? Thanks for helping. |
I have the same problem. I can't share the project either, but I will try to provide as much information as possible. I have typescript compilation disabled in the .csproj ( The errors are not always there. I have been trying to make them appear (there were shown in VS, so I restarted VS). I've tried building the typescript project, building the solution, running tests, running code analysis, running code coverage, etc. Nothing triggers it. Then, just as I was writing the last sentence, the errors appeared. So it seems to be some background tasks that does it? It seems to happen around 2 minutes after I started a build (at least the 2-3 times I tried it out) Timeline: I noticed my project was still using the v2.0.3 About those outdated nuget packages, is that normal? I think I got a popup to upgrade my project typescript tools when I installed the new version of typescript, but it seems it only updated |
I just updated to Typescript 2.2.1 and having this same issue. Its flagging all the the node_modules but the tsc compiler completes without a problem. |
right, it was fixed by wc-catalogue/blaze-elements@cdb94bf sry for delayed answer and thx 4 help! |
@ChrisMBarr May I ask if you got this resolved yet? I've been following the thread and even did the fix suggested by @Hotell couple of posts up but I'm still getting these Errors in Visual Studios. They all seem to be coming from the node_modules folder. |
Would you be able to enable detailed logging and send us the results? Set the system environment variable In my testing I've occasionally seen the project system construct a view of the project that contains the wrong files, causing intermittent errors at unpredictable times. I'd like to see if that may be the cause here. I can provide my email address if you'd rather send the files direct than upload them (billti at microsoft dot com). Thanks. |
@johnlee no, still the same in VS2015. However, I've since started to use Visual Studio 2017 and I have no errors in there! |
@billti Variable added, visual studio (2017) restarted, solution rebuilded, but the log file is not being created. What should I check? |
Is it definitely a system environment variable (i.e. if you open a new command prompt and run |
@Abadii So.... it appears that the reason this was happening was that, even though the JS files were not included, they were failing because they were CommonJS modules.... 🤔 .... In other words, once everything had proper imports / exports, I stopped getting this issue. So, based on the comments of this thread, and the sheer number of fixes, I think that this is one of those red herring errors. As in, when there's X type of JS / Intellisense / compiling issue, then VSCode throws this |
Commenting here because it is the first thing that came up in my google search. I ran into this issue too. 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: "exclude": ["**/*.d.ts", "dist", "node_modules"] I do see the problem if I do this: "exclude": ["dist/**/*.d.ts", "dist", "node_modules"] or this: "exclude": ["**/dist/**/*.d.ts", "dist", "node_modules"] The error occurs despite the fact that the files it is complaining about are clearly inside 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 The first two files are the ones causing the compilation errors. The third file is fine. So it looks like it might be related to how the import / export tree is affecting compilation. |
I just stumbled across this issue while having the same problem, and thought I'd add what mine turned out to be in case other people stumble across it the same way. In my case, I have a monorepo with a separate tsconfig file for each package, that all extend from a base tsconfig. Each packages config has This worked fine for quite a while, then abruptly started throwing this error even though none of the configs had changed. I finally tracked it down by attempting to build the one package that was being reported in the error by itself, rather than building the whole project. Turns out the problem was that I had attempted to have the project import itself. The package name was |
@jasonk This probably is just revealing my ignorance but wouldn't that only work if your monorepo is being bundled together by something that will resolve all those imports (e.g. webpack)? If your monorepo is composed of modules that can be published and used independently changing to relative imports would cause errors no? |
@Ghirigoro No, the problem wasn't that I was using a package path, it's that it was using a package path to import a package from within itself. Even without Typescript, that won't work. Basically what I had done was the equivalent of this:
If you then try to run that with node:
If you replace the package name then it works correctly:
I suspect that what happened was that when the build was run, all of the other packages that were importing from |
Excluding my build dir solved the issue for me |
Most likely, this happens when you try to run one project with two nodes. Also, this problem can occur if the npm packages or git submodules used their own node inside |
I was facing this issue for Webdriver IO / WDIO project. It got resolved when I removed the "wdio.config.js" from "include" in tsconfig.json. |
Fixed this by adding |
I am dealing with the same issue and the problem is only happening if I have:
in my |
If tsc runs fine the first time then errors with this error every time after that it's because it doesn't want to overwrite the compiled files. Just delete the folder then run tsc again, and it'll be fine. |
Is there any way to overwrite the compiled files? Pass some special option in tsconfig maybe? Adding this in package.json
looks hacky in my opinion |
@Arkanic Deleting the folder is a reasonable workaround, but it has downsides. For example if you have an incremental build, or there's other expensive steps required to prepare the build folder. It seems like the problem here is that TS doesn't listen to you when you tell it to exclude something. |
Same problem, I solve It by doing this : Add in package.json and add in tsconfig.json
|
Importing recursively leads to tsc errors > Cannot write file 'client/packages/cozy-client/types/models/note.d.ts' because it would overwrite input file. microsoft/TypeScript#14538 (comment)
Using a mono repo? Check for (implicit and unwanted/accidental) cyclic dependencies! That was what caused this issue for me. I wrote an answer here on StackOverlflow |
If you want to test another solution and check if it works, here is mine: Check if these conditions are met for your project:
Then try changing from import something from '../..' // Or any other relative import to import something from '../../index' // No .ts needed Hope it helps. |
@mkermani144 thanks! |
Due to the way that typescript works in nodejs module resolution, the index.d.ts file will load .ts files incorrectly if you publish the .js and .d.ts files in alongside the .ts files. Unfortunately this causes my version of typescript to attempt to compile the module's .ts files which are not working with typescript 4.4.3! See microsoft/TypeScript#10704 which considers this to be 'working as intended' The solution is to avoid outputting your .js and .d.ts files into the same location as the .ts files. Unfortunately, adding 'dist/index.d.ts' to the types in the package.json caused all imports of '..' (pointing to the /index.ts file) to trigger this issue: microsoft/TypeScript#14538 (comment) which I solved by changing those to '../index' or '../../index' etc. Here is the error I get while trying to compile my project which uses "typescript": "^4.4.3" after `npm install typed-cli: ``` node_modules/typed-cli/src/pipeline.ts:23:9 - error TS2322: Type 'unknown' is not assignable to type 'Error | undefined'. Type 'unknown' is not assignable to type 'Error'. 23 return e; ~~~~~~~~~ Found 1 error. ```
Just had the same issue for Hope someone will find this comment useful. |
@mati-o - "because by accident my source code imported from the dist dir rather than src" To be exact, the auto completion took over at
and incorrectly completed to
or something like that. I think that is a bug. |
I've spent a 2 hours looking for configs solutions, and this post save my day, thanks man! |
TypeScript Version: 2.2.1
When using Visual Studio 2015 Update 3 I am getting hundreds of errors in the error list like:
It looks like this all the time. It doesn't actually prevent building, and everything works just fine, but the error list is distracting and difficult to locate "real" errors when they occur.
My
tsconfig.json
fileHow can I get rid of all these errors?
(I've also posted this question on StackOverflow with no responses yet)
The text was updated successfully, but these errors were encountered: