AOT 清理加载程序出错,无法使用 AOT 模式构建 Angular 应用程序

Error in AOT cleanup loader, failed to build Angular App with AOT mode

听了这么多 Angular AOT 模式,我想试试看。因此,我们将我们的应用程序迁移到 Angular v4.1.2,并进行了所有必要的更改。当我尝试 运行 使用 AOT 模式构建时,在我的 webpack 配置文件中使用以下部分 ngc-webpack 插件配置,我遇到了一些未知错误。

new ngcWebpack.NgcWebpackPlugin({
        disabled: !AOT,
        tsConfig: helpers.root('tsconfig.webpack.json')
      }),

我的tsconfig.webpack.json文件如下:-

{
  "compilerOptions": {
    "target": "es5",
    "module": "es2015",
    "moduleResolution": "node",
    some ts configs
    ....
    ....
     ...
    "lib": [
      "dom",
      "es2015"
    ],
    "baseUrl": ".",
    "paths": {
      "@angular/*": ["node_modules/@angular/*"]
    },

    "typeRoots": [
      "node_modules/@types"
    ],
    "types": [
      "hammerjs",
      "node",
      "jasmine",
      "lodash",
      "source-map",
      "uglify-js",
      "webpack"
    ]
  },
  "exclude": [
    "node_modules",
    "dist",
    "src/**/*.spec.ts",
    "src/**/*.e2e.ts"
  ],
  "awesomeTypescriptLoaderOptions": {
    "forkChecker": true,
    "useWebpackText": true
  },
  "angularCompilerOptions": {
    "genDir": "./compiled",
    "skipMetadataEmit": true
  },
  "compileOnSave": false,
  "buildOnSave": false,
  "atom": {
    "rewriteTsconfig": false
  }
}

当我 运行 构建时,在完成 94% 后,并使用 awesome typescript 加载器成功编译时,aot-clean-compiles 开始运行并抛出如下所示的大堆栈跟踪:-

ERROR in ./src/app/applications/xxx.component.ts
Module build failed: TypeError: refactor.program.getTypeChecker(...).getTypeFromTypeNode is not a function
    at _ctorParameterFromTypeReference (/Users/xxx/sources/migration/yyy/node_modules/src/aot-clean-transformer/loader/text-based-loader/loader.ts:57:58)
    at /Users/xxx/sources/migration/bm_dashbaord/node_modules/src/aot-clean-transformer/loader/text-based-loader/loader.ts:123:12
    at Array.map (native)
    at _addCtorParameters (/Users/xxx/sources/migration/bm_dashbaord/node_modules/src/aot-clean-transformer/loader/text-based-loader/loader.ts:122:46)
    at /Users/xxx/sources/migration/bm_dashbaord/node_modules/src/aot-clean-transformer/loader/text-based-loader/loader.ts:154:11
    at Array.forEach (native)
    at _removeDecorators (/Users/xxx/sources/migration/bm_dashbaord/node_modules/src/aot-clean-transformer/loader/text-based-loader/loader.ts:147:6)
    at Object.aotCleanLoader (/Users/xxx/sources/migration/bm_dashbaord/node_modules/src/aot-clean-transformer/loader/text-based-loader/loader.ts:303:7)

我被这个错误困扰了很长一段时间,无法弄清楚我做错了什么。请有人帮助我。

你可以检查一下版本是不是2.2.2,这个版本应该不会报这个错。