更新了 Angular 至 v16,现在 mat 组件(例如 mat-icon)无法找到并且是未知元素?

问题描述 投票:0回答:1

所以我刚刚将我的项目从 Angular v15 更新到 v16,突然间我抛出了很多缺少导入的错误,例如

error NG8001: 'mat-icon' is not a known element
,但我已根据 app.module.ts 中的文档导入了所有内容:

import {MatIconModule} from '@angular/material/icon';

@NgModule({
  declarations: [...],
  imports: [..., MatIconModule, ...],
  bootstrap: [AppComponent],
})
export class AppModule {}

或者我的 package.json 中缺少某些内容吗?我尝试根据文档更新所有内容:

 "dependencies": {
   "@angular-devkit/core": "^16.2.0",
   "@angular-devkit/schematics": "^16.2.0",
   "@angular/animations": "~16.2.1",
   "@angular/cdk": "^16.2.1",
   "@angular/common": "~16.2.1",
   "@angular/compiler": "~16.2.1",
   "@angular/core": "~16.2.1",
   "@angular/forms": "~16.2.1",
   "@angular/material": "^16.2.1",
   "@angular/platform-browser": "^16.2.1",
   "@angular/platform-browser-dynamic": "~16.2.1",
   "@angular/router": "~16.2.1",
   "bootstrap": "^4.4.1",
   "moment": "^2.26.0",
   "popper.js": "^1.16.0",
   "rxjs": "^6.5.5",
   "tslib": "^2.0.0",
   "xstate": "~4.6.7",
   "zone.js": "~0.13.1"
 }

我尝试删除 node_modules 文件夹并重新安装,运行 npm install 和 npm ci 但到目前为止没有任何效果。我只找到了将缺少的模块添加到 app.module.ts 的提示,但我已经有了这个,有人也遇到这个问题并找到解决方案吗?

angular updating angular16
1个回答
0
投票

我也遇到过同样的问题。为了解决这个问题,我使用了版本 15(编译没有错误),将版本 15 转为独立架构,然后将项目更新为版本 16。 我在这里就这个问题做了一张票:为什么 Angular Material 组件在升级到 Angular 16 后变成未知元素

© www.soinside.com 2019 - 2024. All rights reserved.