小编JP *_*ara的帖子

ng build AOT +从不同包延迟加载时出现Angular 2错误

我有一个 angular 2 应用程序,它是我的应用程序的主要入口。

在这个应用程序中,我正在安装另一个 angular npm 包,其中包含我的模块的所有代码。

这个 npm 包像使用 AOT 的 angular 库一样编译,然后发布到私有 npm。

这是一个带有错误的示例应用程序。 https://github.com/chorew/AngularSample

要查看问题:

  1. 克隆回购
  2. 安装
  3. npm 运行开发:库

在主应用程序模块中,我有这个延迟加载的路由:

const routes: Routes = [
    {   path: 'underwriting',
        loadChildren: '@h2o/underwriting/src/underwriting/underwriting.module#UnderwritingModule' 
    }
];
Run Code Online (Sandbox Code Playgroud)

当我ng build --aot在主应用程序中运行时出现错误。

ERROR in ./src/$$_gendir async
Module not found: Error: Can't resolve 'C:\Users\Juan.Pablo\projects\POC\h2o.web\packages\h2o.app\src\node_modules\@h2o\underwriting\src\underwriting\underwrit
ing.module.d.ngfactory.ts' in 'C:\Users\Juan.Pablo\projects\POC\h2o.web\packages\h2o.app\src\$$_gendir'
@ ./src/$$_gendir async
@ ./~/@angular/core/@angular/core.es5.js
@ ./src/main.ts
@ multi ./src/main.ts
Run Code Online (Sandbox Code Playgroud)

它接缝包名称@h2o/underwriting没有正确转换为路径,并且由于它是模块路径的基础,因此会产生该错误。

ng build 正在尝试查找(检查额外的 src,就像模块是否在主应用程序 src 中一样)

'C:\Users\Juan.Pablo\projects\POC\h2o.web\packages\h2o.app\src\node_modules\@h2o\underwriting\src\underwriting\underwrit
ing.module.d.ngfactory.ts'
Run Code Online (Sandbox Code Playgroud)

什么时候应该

'C:\Users\Juan.Pablo\projects\POC\h2o.web\packages\h2o.app\node_modules\@h2o\underwriting\src\underwriting\underwrit
ing.module.d.ngfactory.ts'
Run Code Online (Sandbox Code Playgroud)

lazy-loading npm angular-cli angular

5
推荐指数
0
解决办法
678
查看次数

标签 统计

angular ×1

angular-cli ×1

lazy-loading ×1

npm ×1