打字稿错误“无法写入文件...因为它会覆盖输入文件。”

2024-04-10

在 Visual Studio 2015 Update 3 中的 Typescript 2.2.1 项目中,我在错误列表中收到数百个错误,例如:

无法写入文件“C:/{{my-project}}/node_modules/buffer-shims/index.js”,因为它会覆盖输入文件。

看起来一直都是这样。它实际上并不会阻止构建,并且一切都工作得很好,但是错误列表会分散注意力,并且很难在发生“真正”错误时找到它们。

这是我的tsconfig.json file

{
  "compileOnSave": true,
  "compilerOptions": {
    "baseUrl": ".",
    "module": "commonjs",
    "noImplicitAny": true,
    "removeComments": true,
    "sourceMap": true,
    "target": "ES5",
    "forceConsistentCasingInFileNames": true,
    "strictNullChecks": true,
    "allowUnreachableCode": false,
    "allowUnusedLabels": false,
    "noFallthroughCasesInSwitch": true,
    "noImplicitReturns": true,
    "noImplicitThis": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,

    "typeRoots": [],
    "types": [] //Explicitly specify an empty array so that the TS2 @types modules are not acquired since we aren't ready for them yet.
  },
  "exclude": ["node_modules"]
}

我怎样才能摆脱所有这些错误?


在我的例子中,我使用的是outDir选项,但不从输入中排除目标目录:

// Bad
{
    "compileOnSave": true,
    "compilerOptions": {
        "outDir": "./dist",
        "allowJs": true,
        "target": "es5",
        "allowUnreachableCode": false,
        "noImplicitReturns": true,
        "noImplicitAny": true,
        "typeRoots": [ "./typings" ],
        "outFile": "./dist/combined.js"
    },
    "include": [
        "./**/*"
    ],
    "exclude": [
        "./plugins/**/*",
        "./typings/**/*"
    ]
}

我们所要做的就是排除以下文件outDir:

// Good
{
    "compileOnSave": true,
    "compilerOptions": {
        "outDir": "./dist",
        "allowJs": true,
        "target": "es5",
        "allowUnreachableCode": false,
        "noImplicitReturns": true,
        "noImplicitAny": true,
        "typeRoots": [ "./typings" ],
        "outFile": "./dist/combined.js"
    },
    "include": [
        "./**/*"
    ],
    "exclude": [
        "./plugins/**/*",
        "./typings/**/*",
        "./dist/**/*" // This is what fixed it!
    ]
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

打字稿错误“无法写入文件...因为它会覆盖输入文件。” 的相关文章

随机推荐