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:
index.ts in tsconfigtsc index.tsdeclaration off in tsconfigindextx to 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.
I dont have any answer on stackoverflow
Do you have a sample code base to repro this issue? Normally this happens when you have a index.d.ts already in your project (could be a generated file from last compilation, as you have declaration set to true here).
The error means that the compiler is trying to write on of its outputs (in this case index.d.ts because you are using --declaration on an input file index.ts or index.tsx presumably) that happens to be an input that was passed to it. the result is a possible data loss (i.e. if index.d.ts is 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 --out or --outDir and excluding the output file or folder in your tsconfig.json.
I have same issue when i rename index.ts to foo.ts and change package.json to
this field "typescript" is something that TS look at. so i am not sure i understand the question.
Do you have a sample code base to repro this issue
Code not matter and in any project this happened for me! by the way this is my code
I exclude index.ts in tsconfig,json for temporary skip this issue.
you have a index.d.ts already in your project
when i delete index.d.ts it solved for once and happened again in the nexts!
if index.d.ts is a file that you wrote by hand
its wried with tsc and when i remove it issue solved for once but happened again
consider using --out or --outDir and excluding the output file or folder in your tsconfig.json.
i don't want to compile in another dir and i don't think its related to this because all files compiled properly and when i change typescript main in package.json its solved but i want index be and default
if i change outDir its solve temporary but i want to set index as main file and as i sad before when in change typescript main in package.json issue happened again !
@zhanbos and @mhegazy Thank you for your attention to this matter
راستی محمد آقا شما ایرانی هستی عزیز ؟
nope. arab :) egyptien to be specific.
I am unable to reproduce this issue with just this infromation. i beleive there is something else specific to your project that we should look at. here is my setup:
c:\test\8468>tree /F /A .
Folder PATH listing for volume OSDisk
Volume serial number is 9E6D-383F
C:\TEST\8468
index.ts
tsconfig.json
No subfolders exist
c:\test\8468>type index.ts
var x = 0;
c:\test\8468>type tsconfig.json
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"moduleResolution": "node",
"declaration": true,
"newLine": "LF",
"preserveConstEnums": true,
"pretty": true,
"experimentalDecorators": true
},
"exclude": [
"node_modules",
"typings"
]
}
c:\test\8468>tsc --v
Version 1.9.0-dev.20160503
c:\test\8468>tsc
c:\test\8468>tree /F /A .
Folder PATH listing for volume OSDisk
Volume serial number is 9E6D-383F
C:\TEST\8468
index.d.ts
index.js
index.ts
tsconfig.json
No subfolders exist
c:\test\8468>tsc
c:\test\8468>tsc
c:\test\8468>
I found the bug!
Source code: https://github.com/AliMD/Node.js-Telegram-Bot-API/tree/v0.0.2-0
I have a example folder and require main module by import * as test from "../";
https://github.com/AliMD/Node.js-Telegram-Bot-API/blob/v0.0.2-0/examples/test-server.ts#L1
Is it my mistake or typescript bug ?
And how can i require my module ?
If its my mistake i'm so sorry for report it as a ts bug here.
Could you please tell me what is the write way to import main module in typescript ?
If you mean to import from the index.ts, you can do import * as test from 'index'. I don't think you can import a folder at once.
I don't think you can import a folder at once.
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.ts is the defintion file for this package, see https://github.com/AliMD/Node.js-Telegram-Bot-API/blob/v0.0.2-0/package.json#L9
so import * as test from "../"; will load package.json, load typings field and then load index.d.t.
solutions
\lib\index.d.tsfor future references tsc --traceResolution should show you what happened. here is what i got running it on your project:
======== Resolving module '../' from 'c:/test/8468/Node.js-Telegram-Bot-API/examples/test-server.ts'. ========
Explicitly specified module resolution kind: 'NodeJs'.
Loading module as file / folder, candidate module location 'c:/test/8468/Node.js-Telegram-Bot-API'.
File 'c:/test/8468/Node.js-Telegram-Bot-API.ts' does not exist.
File 'c:/test/8468/Node.js-Telegram-Bot-API.tsx' does not exist.
File 'c:/test/8468/Node.js-Telegram-Bot-API.d.ts' does not exist.
Found 'package.json' at 'c:/test/8468/Node.js-Telegram-Bot-API/package.json'.
'package.json' has 'typings' field 'index.d.ts' that references 'c:/test/8468/Node.js-Telegram-Bot-API/index.d.ts'.
File 'c:/test/8468/Node.js-Telegram-Bot-API/index.d.ts' exist - use it as a name resolution result.
======== Module name '../' was successfully resolved to 'c:/test/8468/Node.js-Telegram-Bot-API/index.d.ts'. ========
@mhegazy thank you very much
@mhegazy: When executing tsc --traceResolutions it shows me:
error TS5023: Unknown compiler option 'traceresolutions'.
@bennyn it should be traceResolution without the s. I just edited the answers above.
Most helpful comment
for future references
tsc --traceResolutionshould show you what happened. here is what i got running it on your project: