Typescript error “Cannot write file … because it would overwrite input file.”

后端 未结 19 1418
醉梦人生
醉梦人生 2021-02-01 12:04

In my Typescript 2.2.1 project in Visual Studio 2015 Update 3, I am getting hundreds of errors in the error list like:

Cannot write file \'C:/{{my-project

19条回答
  •  终归单人心
    2021-02-01 12:21

    In my instance, I was using the outDir option but not excluding the destination directory from the inputs:

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

    All we have to do is exclude the files in the outDir:

    // Good
    {
        "compileOnSave": true,
        "compilerOptions": {
            "outDir": "./built",
            "allowJs": true,
            "target": "es5",
            "allowUnreachableCode": false,
            "noImplicitReturns": true,
            "noImplicitAny": true,
            "typeRoots": [ "./typings" ],
            "outFile": "./built/combined.js"
        },
        "include": [
            "./**/*"
        ],
        "exclude": [
            "./plugins/**/*",
            "./typings/**/*",
            "./built/**/*" // This is what fixed it!
        ]
    }
    

提交回复
热议问题