错误:e没有模块定义(ɵmod属性)

3

在我的单元测试中,我看到了这个错误:

Error: e does not have a module def (ɵmod property)

我升级到了 Angular v14(

"@angular/cli": "~14.0.0",

)和nx工作区 (

"@nrwl/workspace": "14.4.3",

错误没有指明哪个模块导致了问题:
Error: e does not have a module defmod property)

    at transitiveScopesFor(....)

测试文件:

describe('AppComponent', () => {
  let mockOAuthService;

  beforeEach(waitForAsync(() => {
    // mocks
    Object.defineProperty(window, 'matchMedia', {
      value: jest.fn(() => {
        return { matches: true };
      }),
    });
    mockOAuthService = { logout: jest.fn(), checkAuthentication: () => Promise.resolve(null) };

    TestBed.configureTestingModule({
      declarations: [AppComponent, AddEntriesButtonComponent],
      imports: [
        BrowserAnimationsModule,
        HttpClientModule,
        HsMaterialModule,
        RouterTestingModule,
        RightsModule,
        AuthModule.forRoot(),
        NgxsModule.forRoot(),
      ],
      providers: [{ provide: AuthService, useValue: mockOAuthService }, MediaObserver],
      teardown: { destroyAfterEach: false },
    }).compileComponents();
  }));

  it('should create the app successfully', () => {
    const fixture = TestBed.createComponent(AppComponent);
    const app = fixture.debugElement.componentInstance;
    expect(app).toBeTruthy();
  });
});

我已经被这个问题困扰了好几天,但是无论在哪里都找不到解决方案。

我尝试了删除 node_module 和运行 npm ci 等其他步骤,参考链接:https://github.com/storybookjs/storybook/issues/13958

但这些方法都没有帮助我解决问题。

我的 package.json 文件中已经有了相关配置。

"scripts": {

"postinstall": "ngcc --properties es2020 browser module main && node ./decorate-angular-cli.js",
}

ngx-leaflet-draw: 导入未包含ɵmod属性的模块所述。


你试过npm ci了吗? - MoxxiManagarm
是的,我做了。我删除了 node_modules 并运行了 npm ci。 - Abs
2个回答

0

您正在错误的地方查看问题。错误不在测试文件中。我假设您已经创建了一个自定义组件,想要在多个页面中重复使用。如果您使用的是共享模块,请不要忘记包括 "entryComponents:",如果您没有共享模块,则请确保自定义组件位于 "entryComponents:[customComponentName]" 中。 以下是一个例子:

//shared module

@NgModule({
  imports: [
    IonicModule.forRoot(),
    CommonModule,
    MomentModule,
  ],
  schemas: [CUSTOM_ELEMENTS_SCHEMA],
  declarations: [CustomComponentName],
  entryComponents: [CustomComponentName],
  exports: [CustomComponentName]

})
export class SharedModule {
  static forRoot() {
    return {
      ngModule: SharedModule,
      schemas: [CUSTOM_ELEMENTS_SCHEMA],
    }
  }
}

0
只需将管道包含在“声明”数组中,而不是“导入”中。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接