出错ERROR TS5055:无法写入文件'...',因为它会用allowJS和outDir选项覆盖输入文件

时间:2017-12-11 10:43:25

标签: angular typescript configuration angular5

我收到以下错误:

Building error

我的tsconfig.json文件

{
  "compileOnSave": false,
  "compilerOptions": {
    "allowJs": true,
    //"outFile": "./dist/out-tsc",
    "outDir": "./dist",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],  
    // "exclude": [
    //   "node_modules"
    // ],
    "lib": [
      "es2017",
      "dom"
    ]
  }
}

我的tsconfig.app.json文件:

"extends": "../tsconfig.json",
  "compilerOptions": {
    "allowJs": true,
    //"noEmit": true,
    //"outFile": "../out-tsc/app",
    "outDir": "../out-tsc/app",
    "baseUrl": "./",
    "module": "es2015",
    "types": []
  },
  "exclude": [
    "node_modules",
    "public",
    "test.ts",
    "**/*.spec.ts"
  ]

如果取消注释noEmit项目成功运行,但它是空的。

Angular CLI: 1.6.0
Node: 8.9.1
OS: win32 x64
Angular: 5.1.0

angular/cli: 1.6.0
angular-devkit/build-optimizer: 0.0.35
angular-devkit/core: 0.0.22
angular-devkit/schematics: 0.0.41
ngtools/json-schema: 1.1.0
ngtools/webpack: 1.9.0
schematics/angular: 0.1.10
schematics/schematics: 0.0.10
typescript: 2.4.2
webpack: 3.10.0

相关链接:https://github.com/Microsoft/TypeScript/wiki/FAQ#why-am-i-getting-the-error-ts5055-cannot-write-file-xxxjs-because-it-would-overwrite-input-file-when-using-javascript-files

1 个答案:

答案 0 :(得分:0)

这个tsconfig对我有用:

{
  "compileOnSave": false,
  "compilerOptions": {
    "allowJs": true,
    "outDir": "./out-tsc",

    "allowSyntheticDefaultImports": true,
    "sourceMap": true,
    "declaration": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "traceResolution": true,
    "target": "es5",
    "baseUrl": "./src",
    "paths": {
      // APP
      "app/*": ["./app/*"],
      "components/*": ["./app/components/*"],
      "services/*": ["./app/services/*"],
      "global/*": ["./app/global/*"],
      // ASSETS
      "assets/*": ["./assets/*"],
      // SHARED
      "shared/*": ["./shared/*"],
      "abstract/*": ["./shared/abstract/*"],
      "interfaces/*": ["./shared/interfaces/*"]
    },
    "typeRoots": [
      "node_modules/@types"
    ], 
    "lib": [
      "es2017",
      "dom"
    ]
  }
}

和tsconfig.app:

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/app",
    "baseUrl": "./",
    "module": "es2015",
    "types": []
  },
  "exclude": [
    //"../node_modules/**",
    "public",
    "test.ts",
    "**/*.spec.ts"
  ]
}