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 - Angular 中的单元测试 : Mocking RxJS observable with Jasmine

angular - 将模板内容绑定(bind)到 Observable

typescript - 将类型分配给 Maybe 类型的嵌套类型的属性

javascript - 在 Angular 中组合不重复的数组

jquery - 在自定义 Angular 6+ 库中使用 jQuery

angular - 如何从项目中保存 id 以在下一页上显示特定数据( Angular 4)

node.js - 编辑组件 html 时 Angular CLI 不会重新加载?

angular cli AOT编译错误

javascript - 无法启动 'URL' 因为方案没有注册的处理程序

Angular CLI : Change REST API URL on build