【问题标题】:ngcli 6.1.3 ERROR in ./src/main.ts - Can't resolve './app/app.module.ngfactory'./src/main.ts 中的 ngcli 6.1.3 错误 - 无法解析 './app/app.module.ngfactory'
【发布时间】:2018-08-11 02:22:54
【问题描述】:

我正在使用 angular/cli 6.1.3 并在尝试使用 enableIvy 进行编译时出现以下错误:tsconfig.app.json 中的 true:

ERROR in ./src/main.ts
Module not found: Error: Can't resolve './app/app.module.ngfactory' in 'xxxxPath'

构建命令:

ng build --prod --source-map=false --base-href='/'  --extract-css=true --delete-output-path=true --aot --build-optimizer=true

angular/cli的版本详情

Angular CLI: 6.1.3
Node: 10.7.0
OS: linux x64
Angular: 6.1.2
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.7.3
@angular-devkit/build-angular     0.7.3
@angular-devkit/build-optimizer   0.7.3
@angular-devkit/build-webpack     0.7.3
@angular-devkit/core              0.7.3
@angular-devkit/schematics        0.7.3
@angular/cli                      6.1.3
@ngtools/webpack                  6.1.3
@schematics/angular               0.7.3
@schematics/update                0.7.3
rxjs                              6.2.2
typescript                        2.7.2
webpack                           4.9.2

【问题讨论】:

    标签: angular angular-cli angular-builder


    【解决方案1】:

    这对我有用:

    app.module.ts 文件中删除 BrowserModule,从 ngModule 声明的导入部分和文件顶部的实际 ES5 导入中删除

    并修改main.ts中的引导:

    import { enableProdMode, ɵrenderComponent } from '@angular/core';
    import { environment } from './environments/environment';
    import { AppComponent } from './app/routes/app/app.component';
    
    if (environment.production) {
      enableProdMode();
    }
    
    
    ɵrenderComponent(<any>AppComponent);
    

    主包从 1.4mB 变为 636kB,等不及了。

    【讨论】:

    • 让我试试。很高兴听到大小差异。
    猜你喜欢
    • 2018-06-12
    • 1970-01-01
    • 2018-06-01
    • 2017-07-31
    • 1970-01-01
    • 2023-01-05
    • 1970-01-01
    相关资源
    最近更新 更多