MatCheckbox 未被 ngcc 正确处理,或者与 Angular Ivy 不兼容
MatCheckbox has not been processed correctly by ngcc, or is not compatible with Angular Ivy
我正在尝试将最新的 Angular Material 与 Angular 9 一起使用,但我遇到了以下问题
这是我的 app.modul.ts
import { NgModule } from '@angular/core';
import { CommonModule, CurrencyPipe } from '@angular/common';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { HttpClientJsonpModule } from '@angular/common/http';
import { HttpClientModule } from '@angular/common/http';
import { ModalModule } from 'ngx-bootstrap/modal';
import { BsDropdownModule } from 'ngx-bootstrap/dropdown';
import { CollapseModule } from 'ngx-bootstrap/collapse';
import { TabsModule } from 'ngx-bootstrap/tabs';
import { NgxPaginationModule } from 'ngx-pagination';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { ServiceProxyModule } from '@shared/service-proxies/service-proxy.module';
import { SharedModule } from '@shared/shared.module';
import { HomeComponent } from '@app/home/home.component';
import { AboutComponent } from '@app/about/about.component';
// tenants
import { TenantsComponent } from '@app/tenants/tenants.component';
import { CreateTenantDialogComponent } from './tenants/create-tenant/create-tenant-dialog.component';
import { EditTenantDialogComponent } from './tenants/edit-tenant/edit-tenant-dialog.component';
// roles
import { RolesComponent } from '@app/roles/roles.component';
import { CreateRoleDialogComponent } from './roles/create-role/create-role-dialog.component';
import { EditRoleDialogComponent } from './roles/edit-role/edit-role-dialog.component';
// users
import { UsersComponent } from '@app/users/users.component';
import { CreateUserDialogComponent } from '@app/users/create-user/create-user-dialog.component';
import { EditUserDialogComponent } from '@app/users/edit-user/edit-user-dialog.component';
import { ChangePasswordComponent } from './users/change-password/change-password.component';
import { ResetPasswordDialogComponent } from './users/reset-password/reset-password.component';
// layout
import { HeaderComponent } from './layout/header.component';
import { HeaderLeftNavbarComponent } from './layout/header-left-navbar.component';
import { HeaderLanguageMenuComponent } from './layout/header-language-menu.component';
import { HeaderUserMenuComponent } from './layout/header-user-menu.component';
import { FooterComponent } from './layout/footer.component';
import { SidebarComponent } from './layout/sidebar.component';
import { SidebarLogoComponent } from './layout/sidebar-logo.component';
import { SidebarUserPanelComponent } from './layout/sidebar-user-panel.component';
import { SidebarMenuComponent } from './layout/sidebar-menu.component';
import { ChatComponent } from './chat/chat.component';
import { Chat2Component } from './chat2/chat2.component';
import { CitizenInterestsComponent } from './citizen-interests/citizen-interests.component';
import {MAT_CHECKBOX_CLICK_ACTION, MatCheckbox} from '@angular/material/checkbox';
@NgModule({
declarations: [
AppComponent,
HomeComponent,
AboutComponent,
// tenants
TenantsComponent,
CreateTenantDialogComponent,
EditTenantDialogComponent,
// roles
RolesComponent,
CreateRoleDialogComponent,
EditRoleDialogComponent,
// users
UsersComponent,
CreateUserDialogComponent,
EditUserDialogComponent,
ChangePasswordComponent,
ResetPasswordDialogComponent,
// layout
HeaderComponent,
HeaderLeftNavbarComponent,
HeaderLanguageMenuComponent,
HeaderUserMenuComponent,
FooterComponent,
SidebarComponent,
SidebarLogoComponent,
SidebarUserPanelComponent,
SidebarMenuComponent,
ChatComponent,
Chat2Component,
CitizenInterestsComponent
],
imports: [
CommonModule,
FormsModule,
ReactiveFormsModule,
HttpClientModule,
HttpClientJsonpModule,
ModalModule.forChild(),
BsDropdownModule,
CollapseModule,
TabsModule,
AppRoutingModule,
ServiceProxyModule,
SharedModule,
NgxPaginationModule,
MatCheckbox
],
providers: [],
entryComponents: [
// tenants
CreateTenantDialogComponent,
EditTenantDialogComponent,
// roles
CreateRoleDialogComponent,
EditRoleDialogComponent,
// users
CreateUserDialogComponent,
EditUserDialogComponent,
ResetPasswordDialogComponent
],
})
export class AppModule {}
ERROR in node_modules/@angular/material/checkbox/checkbox.d.ts:56:22 - 错误NG6002:出现在AppModule的NgModule.imports,但是无法解析为 NgModule class。
这可能意味着声明 MatCheckbox 的库 (@angular/material/checkbox) 没有被 ngcc 正确处理,或者与 Angular Ivy 不兼容。检查是否有更新版本的库可用,如果有则更新。还要考虑与库的作者核实,看看该库是否与 Ivy 兼容。
我找到了解决方案here
我导入了 Matcheckbox 而不是 MatCheckboxModule
在那之前,我 运行 这个命令 npm ci 我不知道这是否会影响但我所做的。
在scripts
部分添加文件package.json
如下:
"postinstall": "ngcc --properties es2015 browser module main --first-only --create-ivy-entry-points"
和运行npm install
或yarn install
确保您的导入 class 应该以 **Module 结尾。在我的例子中,我只是导入 MatFormField 并遇到与堆栈的子相同的错误。自从我做了 MatFormFieldModule 它就可以了。
我正在尝试将最新的 Angular Material 与 Angular 9 一起使用,但我遇到了以下问题
这是我的 app.modul.ts
import { NgModule } from '@angular/core';
import { CommonModule, CurrencyPipe } from '@angular/common';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { HttpClientJsonpModule } from '@angular/common/http';
import { HttpClientModule } from '@angular/common/http';
import { ModalModule } from 'ngx-bootstrap/modal';
import { BsDropdownModule } from 'ngx-bootstrap/dropdown';
import { CollapseModule } from 'ngx-bootstrap/collapse';
import { TabsModule } from 'ngx-bootstrap/tabs';
import { NgxPaginationModule } from 'ngx-pagination';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { ServiceProxyModule } from '@shared/service-proxies/service-proxy.module';
import { SharedModule } from '@shared/shared.module';
import { HomeComponent } from '@app/home/home.component';
import { AboutComponent } from '@app/about/about.component';
// tenants
import { TenantsComponent } from '@app/tenants/tenants.component';
import { CreateTenantDialogComponent } from './tenants/create-tenant/create-tenant-dialog.component';
import { EditTenantDialogComponent } from './tenants/edit-tenant/edit-tenant-dialog.component';
// roles
import { RolesComponent } from '@app/roles/roles.component';
import { CreateRoleDialogComponent } from './roles/create-role/create-role-dialog.component';
import { EditRoleDialogComponent } from './roles/edit-role/edit-role-dialog.component';
// users
import { UsersComponent } from '@app/users/users.component';
import { CreateUserDialogComponent } from '@app/users/create-user/create-user-dialog.component';
import { EditUserDialogComponent } from '@app/users/edit-user/edit-user-dialog.component';
import { ChangePasswordComponent } from './users/change-password/change-password.component';
import { ResetPasswordDialogComponent } from './users/reset-password/reset-password.component';
// layout
import { HeaderComponent } from './layout/header.component';
import { HeaderLeftNavbarComponent } from './layout/header-left-navbar.component';
import { HeaderLanguageMenuComponent } from './layout/header-language-menu.component';
import { HeaderUserMenuComponent } from './layout/header-user-menu.component';
import { FooterComponent } from './layout/footer.component';
import { SidebarComponent } from './layout/sidebar.component';
import { SidebarLogoComponent } from './layout/sidebar-logo.component';
import { SidebarUserPanelComponent } from './layout/sidebar-user-panel.component';
import { SidebarMenuComponent } from './layout/sidebar-menu.component';
import { ChatComponent } from './chat/chat.component';
import { Chat2Component } from './chat2/chat2.component';
import { CitizenInterestsComponent } from './citizen-interests/citizen-interests.component';
import {MAT_CHECKBOX_CLICK_ACTION, MatCheckbox} from '@angular/material/checkbox';
@NgModule({
declarations: [
AppComponent,
HomeComponent,
AboutComponent,
// tenants
TenantsComponent,
CreateTenantDialogComponent,
EditTenantDialogComponent,
// roles
RolesComponent,
CreateRoleDialogComponent,
EditRoleDialogComponent,
// users
UsersComponent,
CreateUserDialogComponent,
EditUserDialogComponent,
ChangePasswordComponent,
ResetPasswordDialogComponent,
// layout
HeaderComponent,
HeaderLeftNavbarComponent,
HeaderLanguageMenuComponent,
HeaderUserMenuComponent,
FooterComponent,
SidebarComponent,
SidebarLogoComponent,
SidebarUserPanelComponent,
SidebarMenuComponent,
ChatComponent,
Chat2Component,
CitizenInterestsComponent
],
imports: [
CommonModule,
FormsModule,
ReactiveFormsModule,
HttpClientModule,
HttpClientJsonpModule,
ModalModule.forChild(),
BsDropdownModule,
CollapseModule,
TabsModule,
AppRoutingModule,
ServiceProxyModule,
SharedModule,
NgxPaginationModule,
MatCheckbox
],
providers: [],
entryComponents: [
// tenants
CreateTenantDialogComponent,
EditTenantDialogComponent,
// roles
CreateRoleDialogComponent,
EditRoleDialogComponent,
// users
CreateUserDialogComponent,
EditUserDialogComponent,
ResetPasswordDialogComponent
],
})
export class AppModule {}
ERROR in node_modules/@angular/material/checkbox/checkbox.d.ts:56:22 - 错误NG6002:出现在AppModule的NgModule.imports,但是无法解析为 NgModule class。 这可能意味着声明 MatCheckbox 的库 (@angular/material/checkbox) 没有被 ngcc 正确处理,或者与 Angular Ivy 不兼容。检查是否有更新版本的库可用,如果有则更新。还要考虑与库的作者核实,看看该库是否与 Ivy 兼容。
我找到了解决方案here
我导入了 Matcheckbox 而不是 MatCheckboxModule
在那之前,我 运行 这个命令 npm ci 我不知道这是否会影响但我所做的。
在scripts
部分添加文件package.json
如下:
"postinstall": "ngcc --properties es2015 browser module main --first-only --create-ivy-entry-points"
和运行npm install
或yarn install
确保您的导入 class 应该以 **Module 结尾。在我的例子中,我只是导入 MatFormField 并遇到与堆栈的子相同的错误。自从我做了 MatFormFieldModule 它就可以了。