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"
]
}
This issue solved when:
index.ts
in tsconfig
tsc index.ts
declaration
off in tsconfig
index
to another name!I have same issue when change typescript main file in package.json
for example: rename index.ts to foo.ts
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 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.
Perahaps a better approach is to exclude the target
directory from your build. The key is including the same directory in both the outDir
and exclude
keys:
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"noImplicitAny": false,
"sourceMap": true,
"experimentalDecorators": true,
"outDir": "target",
"declaration": true
},
"exclude": [
"node_modules",
"target"
]
}
In your example folder you wrote import * as test from '../'
see https://github.com/AliMD/Node.js-Telegram-Bot-API/blob/v0.0.2/examples/test-server.ts#L1
It should load your index.ts
, index.d.ts
, or package.json
"typings" field.
And that's the issue. Your package.json
does say that index.d.ts
is the definition file for this package, see https://github.com/AliMD/Node.js-Telegram-Bot-API/blob/v0.0.2/package.json#L9
so import * as test from '../'
will load package.json
, load typings field and then load index.d.ts
and it causes the problem.
Two solutions
Import index file instead of root folder (recommended approach)
e.g. import * as test from '../index'
; or,
Move output to a different folder
e.g. \lib\index.d.ts
.
In both solutions you should load the target file and not the folder. Since you're not loading the root folder anymore the problem will be solved.
Many thanks to everyone else for their answers, for me however the problem was a lot simpler (and stupider). I had let WebStorm select the best import statement for me and overlooked that it included a file from the "dist" directory (this is what I have my output set to.
Once that cause was found the error made much more sense as it was indeed trying to write to the output file that was being used as it's input.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With