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:
- exclude
index.ts
intsconfig
- run
tsc index.ts
- Turn
declaration
off intsconfig
- rename
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.
5
Answers
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
, orpackage.json
"typings" field.And that's the issue. Your
package.json
does say thatindex.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#L9so
import * as test from '../'
will loadpackage.json
, load typings field and then loadindex.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.
libindex.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.
I had this very same problem, and it was super simple to fix. I deleted node_modules, then deleting the typings folder.
in package.json I have these in
then ran the commands:
Perahaps a better approach is to exclude the
target
directory from your build. The key is including the same directory in both theoutDir
andexclude
keys: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.
In my case I was missing
"include": ["./src/**/*.ts"]
in tsconfig.json even though I had set the following:Typescript was probably confused as to which files it needed to include and probably thought my file that was built in
./build/index.d.ts
was an input file.