[英]Angular 9 unable to run storybooks on ivy enabled library if library imports another ivy enabled library
[英]Angular Library with Ivy enabled fails to load
我正在嘗試創建一個角度庫項目,但在控制台中出現此錯誤
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
創建了一個新的 angular 項目,然后用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
構建它,所有構建都很好,並且我使用鏈接將庫包含在演示應用程序中,在我運行的庫的 dist 文件夾中運行yarn link
並在根演示應用程序文件夾中運行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 start
或ng 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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.