-
Notifications
You must be signed in to change notification settings - Fork 12.8k
TypeScript complains about overwriting .d.ts files that are potentially known outputs #16749
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
Comments
nope, it's not because of the include property, I removed it, and same problem. this is a weird one folks. |
If you remove the It would be helpful to get feedback from others on this. |
But generated .d.ts files are not input files! As you can see in this case that it's being autogenerated. Why would tsc complain? |
|
I still don't think the configuration is appropriate - |
Daniel, sorry if I wasnt clear ( i am the same person as oresoftware). But two days ago on this thread I clearly stated that the same exact problem occurs when I remove the includes entry altogether from tsconfig.json. This issue does not have to do with the includes property. |
As Daniel stated:
Outputting to the same path that your input from is a folly that will cause you endless heartache. How do you expect |
@kitsonk this is almost certainly operator error on my part - I have 10+ typescript projects and only this one is suffering from the problem, and I have such a simple configuration, I don't know what's going on yet. But as far "How do you expect", the answer is simple.. I have an And therein lies my bemusement. |
I updated the original question - I have only one tsconfig.json file in the project and this is barebones and is causing the problem still.
|
here is a link to the project, if you want to see the problem for yourself: |
If I do this: "include":[
"*.ts",
"!*.d.ts"
] then it does not complain - however, I swear I have other projects where I do not need to use that |
What version of TSC do you use? When using TSC 1.8 I have the problem below but is gone with version 2.4: If you generate output in same folder as input you can get the error
This is (off course) because tsc reads also the *.d.ts files. But when I add the option |
I also have this issue. I have turned |
potentially solved by using the {
"compilerOptions": {
"outDir": "dist",
"rootDir": "src",
},
"include": [
"src"
]
} |
I'm getting bit by this. Both cases are valid. I would prefer an option to overwrite them, e.g. Meanwhile, |
(my use case is generating |
I am facing a similar issue with the following {
"compilerOptions": {
"alwaysStrict": true,
"charset": "utf-8",
"composite": true,
"declaration": true,
"declarationMap": true,
"incremental": true,
"inlineSourceMap": true,
"lib": ["ES2018"],
"module": "CommonJS",
"moduleResolution": "node",
"resolveJsonModule": true,
"strict": true
},
"include": [
"**/*.ts",
"**/package.json"
]
} And then whenever I try to do The reason I think this is incorrect behavior is because it differs to the behavior around |
I've also run into this issue which I documented here. Quoting:
|
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. Thought this might be a clue worth mentioning... |
At the very least there should be a flag that allows you to force an overwrite. |
"exclude": [
"src/*.d.ts",
"src/builder/*.d.ts"
],
"include": [
"src/*.js",
"src/builder/*.js"
], This also gives the error although I explicitly only include .js and exclude .d.ts. Still complains about input .d.ts overwrite... |
Hello everyone. I was facing this error today and I found another possible cause for you. Check if you are importing something like: My fix was to import from You'll still need to to exclude
Can anyone else confirm? |
Remove unmaintanable packages, [Table], [PinchZoomSliderModal]. Fix typescript build unable to overwrite issue. - Related microsoft/TypeScript#16749
Remove unmaintanable packages, [Table], [PinchZoomSliderModal]. Fix typescript build unable to overwrite issue. - Related microsoft/TypeScript#16749 Migrate to `emotion` to resolve complex typescript issues.
I faced the same issue, I've fixed it by ignoring test files and by removing logic from the index file, using it only for exports. |
You can use |
I am having the same issue with vitest + coverage with istanbul. It seems as if vitest is transpiling the code again and trying to replace existing files that have already been generated and are being used as input. If i add
to I am still wondering whether this will impact other workflows, e.g. packaging and publishing to npm... |
@DanielRosenwasser From the perspective of someone using only JavaScript (via JSDocs in For my use case, I'm working in a monorepo. TypeScript is able to type my entire monorepo with JSDocs. So I don't use the generated {
"compilerOptions": {
"target": "ES2020",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"strict": true,
"allowJs": true,
"checkJs": true,
"declaration": true,
"emitDeclarationOnly": true,
"forceConsistentCasingInFileNames": true
},
"include": ["./**/*.js"],
"exclude": ["./index.js", "./**/*.d.ts"]
} Ideally, for build + release, I would simply say, "Generate the output During a build + release, it's more convenient for me to say, "Generate (or re-generate) the output In the end, I'm just going to write "prebuild: npm run remove-output-d-ts-files" and "build: tsc" as npm scripts for the build step. But if developers have to do this, it's a sign that they know what's an input and what's an output. To me, it would make sense if TypeScript was updated so that this extra inconvenient step wouldn't be necessary anymore. |
Agree that output |
I was facing this same error for two reasons:
Delete both solved the problem. |
SolutionIn short, this: {
"compilerOptions": {
"rootDir": "src",
"outDir": "dist",
}
} The solution here is to define both Any config other other than this will eventually cause this error. WhyThe error is not clear enough, but it happens because TypeScript is processing all supported files in a folder, then it outputs them in the same folder. Some of these files (d.ts) fall back into the "files to process" list, so when it tries to, again, write the file in the same spot, it complains that it's the same as the input file. This is not a bug. However deciphering TypeScript errors is near impossible to anyone who doesn't spend hours trying to figure out what TypeScript is doing. It could have been:
|
I'm getting this error in one of my Yarn workspaces despite having a separate Edit: It seems to happen when I use the same directory as Edit 2: It turned out to be because some random file in packages/frontend/tsconfig.json{ "extends": "../../configs/tsconfig.json", "compilerOptions": { "rootDir": "src", "outDir": "dist", "composite": true, "jsx": "react-jsx", "jsxImportSource": "@emotion/react", "paths": { "@/*": ["./src/*"] } }, "include": ["src"], "references": [ { "path": "../shared" }, { "path": "../file-system" } ] } configs/tsconfig.json{ "compilerOptions": { "target": "es2017", "module": "esnext", "moduleResolution": "bundler", "lib": ["dom", "es2019"], "types": ["@types/jest", "jest-extended"], "strict": true, "alwaysStrict": true, "strictFunctionTypes": true, "strictNullChecks": true, "strictPropertyInitialization": true, "esModuleInterop": true, "skipLibCheck": true, "forceConsistentCasingInFileNames": true, "noImplicitAny": true, "noImplicitReturns": true, "noImplicitThis": true, "noFallthroughCasesInSwitch": true, "noUnusedLocals": true, "noUnusedParameters": true, "emitDecoratorMetadata": true, "experimentalDecorators": true, "downlevelIteration": true, "declaration": true, "pretty": true } } packages/frontend/package.json{ "name": "@untitled/frontend", "private": true, "version": "1.0.0", "type": "module", "license": "MIT", "main": "dist/index.js", "types": "dist/index.d.ts", "dependencies": { "@untitled/file-system": "workspace:^", "@untitled/shared": "workspace:^" }, "packageManager": "[email protected]" } |
Using tsc at the command line, I got
why? :)
my tsconfig.json file is as follows
The text was updated successfully, but these errors were encountered: