首页 > 解决方案 > 无法在 Angular 5 的 tsconfig 中使用模块 esnext 进行动态模块导入

问题描述

我正在尝试在我的 angular 5 应用程序中进行动态导入。根据这个github issue,评论说 usingmodule: esnext应该使它工作。这是我的配置

"compilerOptions": {
  "outDir": "./dist/out-tsc",
  "noEmitOnError": true,
  "target": "es2016",
  "module": "esnext",
  "experimentalDecorators": true,
  "emitDecoratorMetadata": true,
  "sourceMap": true,
  "moduleResolution": "node",
  "declaration": false,
  "lib": [
    "es2016",
    "dom"
  ]
}

注意:没有es2016in lib 会给我带来错误,因为我在代码中使用.find()and .includeson Array's。

编译时出现此错误

error TS1323: Dynamic import cannot be used when targeting ECMAScript 2015 modules.

不知道为什么当我有module: esnext.

标签: angularangular5

解决方案


我想通了。事实证明这是一个愚蠢的错误,我正在tsconfig.json根文件夹中进行编辑,而文件夹中还有另一个tsconfig.app.json覆盖src了我的设置。


推荐阅读