TypeScript 错误:无法写入文件“index.d.ts”,因为它会覆盖输入文件

2023-12-21

我运行时遇到问题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"
  ]
}

此问题在以下情况下得到解决:

  1. exclude index.ts in tsconfig
  2. run tsc index.ts
  3. Turn declaration off in tsconfig
  4. rename index以另一个名字!

更改 package.json 中的打字稿主文件时,我遇到同样的问题
例如:将index.ts重命名为foo.ts

change package.json to

"typescript": {
  "main": "foo.ts"
}

tsc 错误:

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

无论文件内容如何,​​任何代码内容都有相同的问题!

我能做什么来修复它?

源代码:https://github.com/AliMD/Node.js-Telegram-Bot-API/tree/v0.0.2-0 https://github.com/AliMD/Node.js-Telegram-Bot-API/tree/v0.0.2-0
先感谢您。


也许更好的方法是排除target您构建的目录。关键是在两个目录中包含相同的目录outDir and exclude keys:

{
    "compilerOptions": {
        "module": "commonjs",
        "target": "es6",
        "noImplicitAny": false,
        "sourceMap": true,
        "experimentalDecorators": true,
        "outDir": "target",
        "declaration": true
    },
    "exclude": [
        "node_modules",
        "target"
    ]
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

TypeScript 错误:无法写入文件“index.d.ts”,因为它会覆盖输入文件 的相关文章

随机推荐