无法使用声明覆盖dir

时间:2020-08-04 12:46:20

标签: node.js typescript

我正在使用Typescript,在tsconfig.json中出现此错误:

无法写入文件'c:/michael/Documents/razor/lib/client.d.ts',因为它会覆盖输入文件。

这是我的tsconfig.json内容:

{
    "compilerOptions": {
        "target": "es6",
        "module": "commonjs",
        "moduleResolution": "Node",
        "sourceMap": true,
        "outDir": "./lib",
        "removeComments": true,
        "strict": true,
        "esModuleInterop": true,
        "skipLibCheck": true,
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true,
        "resolveJsonModule": true,
        "declaration": true
    },
    "exclude": [
        "node_modules",
        "test"
    ]
}

如您所见,我已启用declaration: true来导出d.ts文件。 这是我的项目文件夹结构:

/lib
/node_modules
/src
/test
.gitignore
.npmignore
razor-1.0.0.tgz
package.json
packages-lock.json
readme.md
tsconfig.json

如果我尝试运行tsc -p,则无法编译,因此每次必须手动删除包含已编译项目的文件夹lib时。

我该如何解决?

1 个答案:

答案 0 :(得分:2)

TypeScript在编译时正在从lib目录中拾取文件。因此,该错误。尝试将lib添加到exclude数组中。