TypeScript error: Cannot write file 'index.d.ts' because it would overwrite input file

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.


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"
    ]
}

Tags:

Typescript