启用了Ivy的Angular Library无法加载

我正在尝试创建一个角度库项目,但是在控制台中出现此错误

Uncaught TypeError: Cannot read property 'id' of undefined
    at registerNgModuleType (core.js:34470)
    at core.js:34488
    at Array.forEach (<anonymous>)
    at registerNgModuleType (core.js:34484)
    at new NgModuleFactory$1 (core.js:34651)
    at compileNgModuleFactory__POST_R3__ (core.js:40286)
    at PlatformRef.bootstrapModule (core.js:40609)
    at Module../src/main.ts (main.ts:11)
    at __webpack_require__ (bootstrap:79)
    at Object.0 (main.ts:12)

我用ng new --enable-ivy创建了一个新的角度项目,然后用ng g library my-lib添加了一个库。我的图书馆的次级端点带有一个模块(如下),因此导入将为import { MyLibModule } from 'my-lib/secondary';

@NgModule({
  imports: [
    Commonmodule
  ],declarations: [
    MyLibDirective
  ],exports: [
    MyLibDirective
  ]
})
export class MyLibModule {
  public static forRoot(): ModuleWithProviders {
    return {
      ngModule: MyLibModule,providers: []
    };
  }
}

我使用ng build my-lib进行了构建,一切都构建良好,并且我使用链接将库包含在演示应用程序中,运行的库yarn link的dist文件夹中以及根演示中我运行yarn link my-lib的应用文件夹,然后将模块包含在AppModule

的导入中
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { MyLibModule } from 'my-lib/secondary';

import { AppComponent } from './app.component';

@NgModule({
  declarations: [
    AppComponent
  ],imports: [
    BrowserModule,MyLibModule.forRoot()
  ],providers: [],bootstrap: [AppComponent]
})
export class AppModule { }

但是,当我运行yarn startng serve时,一切正常,但是在控制台中出现上述错误,在浏览器中调试此错误,似乎库中的ngModuleDef属性模块不存在,有人知道为什么会这样吗?

注意:如果我关闭Ivy,这不是问题,但是ng9即将推出时,这并不是一个切实可行的解决方案,我想知道我对库做错了什么(如果有的话)

ng version的输出

     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__,|\__,_|_|\__,_|_|       \____|_____|___|
                |___/


Angular CLI: 8.3.21
Node: 12.12.0
OS: darwin x64
Angular: 8.2.14
... animations,common,compiler,compiler-cli,core,forms
... language-service,platform-browser,platform-browser-dynamic
... router

Package                            Version
------------------------------------------------------------
@angular-devkit/architect          0.803.21
@angular-devkit/build-angular      0.803.21
@angular-devkit/build-ng-packagr   0.803.21
@angular-devkit/build-optimizer    0.803.21
@angular-devkit/build-webpack      0.803.21
@angular-devkit/core               8.3.21
@angular-devkit/schematics         8.3.21
@angular/cli                       8.3.21
@ngtools/webpack                   8.3.21
@schematics/angular                8.3.21
@schematics/update                 0.803.21
ng-packagr                         5.7.1
rxjs                               6.5.4
typescript                         3.5.3
webpack                            4.39.2
songlihai 回答:启用了Ivy的Angular Library无法加载

  1. npm uninstall -g @angular/cli
  2. npm install -g @angular/cli@8.3.19 --检查你的项目CLI版本 3.ng_Modules 从本地文件夹中删除
  3. npm 安装
本文链接:https://www.f2er.com/2830023.html

大家都在问