TypeScript: [bug] tsc error: cannot write file 'main.d.ts' because it would overwrite input file
Excuse me for writing my question here but i guess its a bug.
I have issue when run tsc
error TS5055: Cannot write file 'index.d.ts' because it would overwrite input file.
my tsconfig.json:
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"moduleResolution": "node",
"declaration": true,
"newLine": "LF",
"preserveConstEnums": true,
"pretty": true,
"experimentalDecorators": true
},
"exclude": [
"node_modules",
"typings"
]
}
TypeScript Version: 1.8.10
This issue solved when:
- Exclude
index.tsintsconfig - Run
tsc index.ts - Turn
declarationoff intsconfig - Rename
indextxto foo.ts!
I have same issue when i rename index.ts to foo.ts and change package.json to
"typescript": {
"main": "foo.ts"
}
tsc error:
error TS5055: Cannot write file 'index.d.ts' because it would overwrite input file.
content of index file no mater, any code content has same issue!
What can i do for fix it ?
Source code: https://github.com/AliMD/Node.js-Telegram-Bot-API/tree/v0.0.2-0
Thank you in advance and excuse me again for asking my question here.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 17 (10 by maintainers)
for future references
tsc --traceResolutionshould show you what happened. here is what i got running it on your project:you can, it shoudl load you index.ts, index.d.ts, or package.json “typings” field.
And this is the issue. your package.json does say that
index.d.tsis the defintion file for this package, see https://github.com/AliMD/Node.js-Telegram-Bot-API/blob/v0.0.2-0/package.json#L9 soimport * as test from "../";will load package.json, loadtypingsfield and then loadindex.d.t.solutions
\lib\index.d.tsIf you mean to import from the
index.ts, you can doimport * as test from 'index'. I don’t think you can import a folder at once.nope. arab 😃 egyptien to be specific.
The error means that the compiler is trying to write on of its outputs (in this case
index.d.tsbecause you are using--declarationon an input fileindex.tsorindex.tsxpresumably) that happens to be an input that was passed to it. the result is a possible data loss (i.e. ifindex.d.tsis a file that you wrote by hand, and did not mean for it to be overwritten with the one that is emitted from the compiler.When you use tsconfig.json, it sucks in all the files in the containing folder and its subfolders.
consider using
--outor--outDirand excluding the output file or folder in your tsconfig.json.