【发布时间】:2020-11-15 20:12:34
【问题描述】:
我用 Angular 9 和最后一个版本的材料做了一个新项目。当我导入一些 Material 的类时,我遇到了这个错误:
node_modules/@angular/material/form-field/label.d.ts:10:22 中的错误 - 错误 NG6002:出现在 MaterialModule 的 NgModule.imports 中,但无法解析为 NgModule 类。
这可能意味着声明 MatLabel 的库 (@angular/material/form-field) 没有被 ngcc 正确处理,或者与 Angular Ivy 不兼容。检查是否有更新版本的库可用,如果有则更新。还可以考虑与图书馆的作者核实,看看图书馆是否应该与 Ivy 兼容。
10 导出声明类 MatLabel { ~~~~~~~~ node_modules/@angular/material/form-field/hint.d.ts:20:22 - 错误 NG6002:出现在 MaterialModule 的 NgModule.imports 中,但无法解析为 NgModule 类。
这可能意味着声明 MatHint 的库 (@angular/material/form-field) 未被 ngcc 正确处理,或者与 Angular Ivy 不兼容。检查是否有更新版本的库可用,如果有则更新。还可以考虑与图书馆的作者核实,看看图书馆是否应该与 Ivy 兼容。
20 出口声明类 MatHint { ~~~~~~~ src/app/material.module.ts:12:14 - 错误 NG6002:出现在 AppModule 的 NgModule.imports 中,但无法解析为 NgModule 类。
是否缺少@NgModule 注解?
12 导出类 MaterialModule {} ~~~~~~~~~~~~~~~~~
node_modules/@angular/material/form-field/label.d.ts:10:22 中的错误 - 错误 NG6002:出现在 MaterialModule 的 NgModule.imports 中,但无法解析为 NgModule 类。
这可能意味着声明 MatLabel 的库 (@angular/material/form-field) 没有被 ngcc 正确处理,或者与 Angular Ivy 不兼容。检查是否有更新版本的库可用,如果有则更新。还可以考虑与图书馆的作者核实,看看图书馆是否应该与 Ivy 兼容。
10 导出声明类 MatLabel { ~~~~~~~~ node_modules/@angular/material/form-field/hint.d.ts:20:22 - 错误 NG6002:出现在 MaterialModule 的 NgModule.imports 中,但无法解析为 NgModule 类。
这可能意味着声明 MatHint 的库 (@angular/material/form-field) 未被 ngcc 正确处理,或者与 Angular Ivy 不兼容。检查是否有更新版本的库可用,如果有则更新。还可以考虑与图书馆的作者核实,看看图书馆是否应该与 Ivy 兼容。
20 出口声明类 MatHint { ~~~~~~~ src/app/material.module.ts:12:14 - 错误 NG6002:出现在 AppModule 的 NgModule.imports 中,但无法解析为 NgModule 类。
是否缺少@NgModule 注解?
12 导出类 MaterialModule {} ~~~~~~~~~~~~~~~~~
material.module.ts
import { NgModule } from '@angular/core';
import {
MatFormFieldModule,
MatLabel,
MatHint,
} from '@angular/material/form-field';
@NgModule({
imports: [MatFormFieldModule, MatLabel, MatHint],
exports: [MatFormFieldModule, MatLabel, MatHint],
})
export class MaterialModule {}
app.modules.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { MaterialModule } from './material.module';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { CarouselComponent } from './carousel/carousel.component';
import { DashboardComponent } from './dashboard/dashboard.component';
import { CrudComponent } from './crud/crud.component';
import { ProfileComponent } from './profile/profile.component';
import { LayoutComponent } from './layout/layout.component';
import { FooterComponent } from './layout/footer/footer.component';
import { HomeComponent } from './home/home.component';
import { AboutComponent } from './about/about.component';
import { LoginComponent } from './login/login.component';
import { PrivHeaderComponent } from './layout/priv-header/priv-header.component';
import { PrivMenuComponent } from './layout/priv-menu/priv-menu.component';
import { MainMenuComponent } from './layout/main-menu/main-menu.component';
import { MainHeaderComponent } from './layout/main-header/main-header.component';
@NgModule({
declarations: [
AppComponent,
CarouselComponent,
DashboardComponent,
CrudComponent,
ProfileComponent,
LayoutComponent,
FooterComponent,
HomeComponent,
AboutComponent,
LoginComponent,
PrivHeaderComponent,
PrivMenuComponent,
MainMenuComponent,
MainHeaderComponent,
],
imports: [
BrowserModule,
FormsModule,
MaterialModule,
ReactiveFormsModule,
AppRoutingModule,
BrowserAnimationsModule,
],
providers: [],
bootstrap: [AppComponent],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
})
export class AppModule {}
package.json
{
"name": "mini-aplicacion",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "~10.0.5",
"@angular/cdk": "^10.1.0",
"@angular/common": "~10.0.5",
"@angular/compiler": "~10.0.5",
"@angular/core": "~10.0.5",
"@angular/forms": "~10.0.5",
"@angular/material": "^10.1.0",
"@angular/platform-browser": "~10.0.5",
"@angular/platform-browser-dynamic": "~10.0.5",
"@angular/router": "~10.0.5",
"rxjs": "~6.5.4",
"tslib": "^2.0.0",
"zone.js": "~0.10.2"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.1000.4",
"@angular/cli": "~10.0.4",
"@angular/compiler-cli": "~10.0.5",
"@types/node": "^12.11.1",
"@types/jasmine": "~3.5.0",
"@types/jasminewd2": "~2.0.3",
"codelyzer": "^6.0.0",
"jasmine-core": "~3.5.0",
"jasmine-spec-reporter": "~5.0.0",
"karma": "~5.0.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage-istanbul-reporter": "~3.0.2",
"karma-jasmine": "~3.3.0",
"karma-jasmine-html-reporter": "^1.5.0",
"protractor": "~7.0.0",
"ts-node": "~8.3.0",
"tslint": "~6.1.0",
"typescript": "~3.9.7"
}
}
我试图删除 node_modules 并重新安装它。另外,我将 Angular 版本更新为 10 和 Material 版本,但问题仍然存在。
我查看了其他类似问题,但没有一个解决方案可以解决我的问题。
【问题讨论】:
标签: angular angular-material angular-ivy