angular - 错误 TS5023 : Unknown compiler option 'compilerOptions'

标签 angular typescript angular-cli

我正在尝试将我的 Angular4 应用程序更新到 Angular5。

我尝试按照官方网站建议的步骤进行操作,但现在我无法再编译,并且出现此错误:

错误 TS5023:未知的编译器选项“compilerOptions”。

这是组件的版本:

Angular CLI: 1.6.8
Node: 7.4.0
OS: win32 x64
Angular: 5.0.0
... animations, common, compiler, compiler-cli, core, forms
... http, platform-browser, platform-browser-dynamic
... platform-server, router

@angular/cli: 1.6.8
@angular-devkit/build-optimizer: 0.0.42
@angular-devkit/core: 0.0.29
@angular-devkit/schematics: 0.0.52
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.9.8
@schematics/angular: 0.1.17
typescript: 2.7.1
webpack: 3.10.0

tsconfig.json

{
  "compilerOptions": {
    "baseUrl": "",
    "declaration": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": ["es6", "dom"],
    "mapRoot": "./",
    "module": "es6",
    "moduleResolution": "node",
    "outDir": "../dist/out-tsc",
    "sourceMap": true,
    "target": "es5",
    "typeRoots": [
      "../node_modules/@types"
    ],
    "types": [
      "jquery",
      "jqueryui",
      "jasmine",
      "datatables.net",
      "datatables.net-select"
    ],
    "compilerOptions": {
      "types" : [ "node" ]
 }

  }
}

我该如何解决?

感谢支持

最佳答案

错误消息中提到了您的 tsconfig.json 格式错误。您在原始 compilerOptions 对象中有一个额外的 compilerOptions 属性。它应该像下面这样

{
  "compilerOptions": {
    "baseUrl": "",
    "declaration": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": ["es6", "dom"],
    "mapRoot": "./",
    "module": "es6",
    "moduleResolution": "node",
    "outDir": "../dist/out-tsc",
    "sourceMap": true,
    "target": "es5",
    "typeRoots": [
      "../node_modules/@types"
    ],
    "types": [
      "jquery",
      "jqueryui",
      "jasmine",
      "datatables.net",
      "datatables.net-select"
    ]

  }
}

然而,typeRoots 将优先于此处的 types,并且所有包将从 "../node_modules/@types" 加载.检查此链接以了解所有选项。

https://www.typescriptlang.org/docs/handbook/compiler-options.html

http://www.typescriptlang.org/docs/handbook/tsconfig-json.html

关于angular - 错误 TS5023 : Unknown compiler option 'compilerOptions' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48789962/

相关文章:

angular - 如何将 ngrx/store 与 Angular 路由器防护装置连接

javascript - Nodejs 中的 RXJS PostgreSQL 背压

node.js - 如何在发布 NPM 模块时管理外部 .d.ts 依赖项?

javascript - 类型 'any[]' 的参数不可分配给类型 'A' 的参数。类型 'a' 中缺少属性 'any[]'

Angular cli : getting it ready for production

node.js - 将@angular/cli 与服务器端 EJS 模板集成

typescript - Angular 2找不到文件名 'Set'

angular - 如何让 Typescript 抛出运行时错误?

angular - ionic2 rc0 中找不到组件工厂错误

node.js - 如何不对 Angular2 环境变量(例如 API URL)进行硬编码