【发布时间】:2021-10-23 17:36:30
【问题描述】:
所以我遇到了一个编译错误,当我输入 ng serve 以在本地查看我的更改时,我的所有组件上的所有导入模块都收到以下错误。
1. If 'mat-card-title' is an Angular component, then verify that it is part of this module.
2. If 'mat-card-title' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
22 <mat-card-title>Register</mat-card-title>
~~~~~~~~~~~~~~~~
src/app/landing-page/landing-page.component.ts:8:16
8 templateUrl: './landing-page.component.html',
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Error occurs in the template of component LandingPageComponent.
我知道这发生在我从 git 存储库的另一个分支中提取之后,并且在我的项目中添加了一个名为“node_modules”的新文件夹,在此之前一切都很好。这以前没有发生过,那么我可以做些什么来缓解这个问题?
是否需要将模块再次导入到各个组件的 .ts 文件中?
控制台错误截图:
谢谢!
【问题讨论】:
-
请不要将
node_modules文件夹检查到源代码管理中。package.json和package-lock.json就是您所需要的。如果您删除package-lock.json和node_modules文件夹并再次运行npm install它应该可以解决。 (package-lock 和 node_modules 都将在运行 install 命令后重新创建,只需确保在 .gitignore 文件中包含 node_modules)。
标签: html angular typescript