按照 angular.io 中的步骤在 Angular 中找不到模块错误

Cant find Module error in Angular when following the steps from angular.io

这是我根据 angular.io 文档构建的第一个 Angular 应用程序。我按照他们提到的相同步骤进行操作,我发现当我生成新组件时,它们没有被添加到 app.module,所以我尝试添加它们,但在这里我收到以下错误

Cannot find module './product-alerts/product-alerts.component'.

此应用是在 stackblitz 中构建的,因此请找到我的项目的链接。

编辑器网址:https://stackblitz.com/edit/angular-tejatest1

这是因为您的产品提醒组件在应用程序文件夹之外。像这样更改您在模块中的导入:或将您的产品警报移动到应用程序文件夹中。

试试这个:

app.module.ts

import { ProductAlertsComponent } from '../product-alerts/product-alerts.component';

steps and the solution was IT-Crowd-like 之后发现了一个类似的问题:保存项目并重新加载页面!

有时,当 Stackblitz 中的组件被创建,然后被删除时,也会发生这种情况。导入恰好不会自动删除。这可能会导致混乱的情况。