【发布时间】:2020-09-07 05:58:40
【问题描述】:
我对 Web 开发非常陌生,我正在尝试熟悉构建 Angular 表单。我遇到了一个问题,每次我使用 npm start 或 ng serve 启动一个 Angular 项目并转到本地主机时,它都会给我一个错误“Cannot GET /”。
如果我关闭所有内容,删除项目文件夹中的 node_modules,运行npm install,然后再次运行npm start,它将起作用。如果我关闭终端并尝试再次运行该项目,我会回到同样的错误。基本上我只能运行该项目一次,然后我必须去重复删除 node_modules 等的过程(这本身就是一种痛苦,因为我还没有找到删除 node_modules 的快速方法。)
我正在使用 Windows 以及 2020 年 4 月发布的 VS Code 和 Angular 9。如果我可以提供任何信息,请告诉我:代码、文件等,正如我所说,我对此很陌生,而不是真的很确定我可以在哪里尝试解决这个问题。谢谢!
更新:这是我在终端中的内容。错误在底部,它与 MatDialogRef 有关,但老实说,我只是忽略了这一点,因为无论如何我都会遇到同样的错误,即使我的项目正确打开。我相信这个错误是由他们对 Angular 9 所做的一些更改引起的,但我不确定如何修复它。
更新 2:我将 MatDialogRef 的路径编辑为 @angular/materials/dialog,从而修复了该错误,但现在我收到了一大堆以前没有发生过的相同类型的错误。请看下文。
ERROR in src/app/app-layer/app-layer.component.html:2:35 - error TS2339: Property 'isLinear' does not exist on type 'AppLayerComponent'.
2 <mat-vertical-stepper [linear] = "isLinear" #stepper>
~~~~~~~~
src/app/app-layer/app-layer.component.ts:6:16
6 templateUrl: './app-layer.component.html',
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Error occurs in the template of component AppLayerComponent.
下面是我通过添加/dialog修复的原始错误
> app-frontend@0.0.0 start C:\Users\u123\Documents\Angular\app-frontend
> ng serve
chunk {main} main.js, main.js.map (main) 2.04 kB [initial] [rendered]
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 700 bytes [initial] [rendered]
chunk {runtime} runtime.js, runtime.js.map (runtime) 6.15 kB [entry] [rendered]
chunk {styles} styles.js, styles.js.map (styles) 1.28 MB [initial] [rendered]
chunk {vendor} vendor.js, vendor.js.map (vendor) 339 kB [initial] [rendered]
Date: 2020-05-20T18:57:35.818Z - Time: 16760ms
ERROR in node_modules/gcui/lib/delete-confirmation-dialog/delete-confirmation-dialog.component.d.ts:1:30 - error TS2306: File 'C:/Users/u123/Documents/Angular/app-frontend/node_modules/@angular/material/index.d.ts' is not a module.
1 import { MatDialogRef } from '@angular/material';
~~~~~~~~~~~~~~~~~~~
** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
【问题讨论】:
-
您能否在终端和控制台中向我们显示错误日志
-
我更详细地编辑了帖子,并将终端输出。控制台中的错误日志是什么意思?谢谢。
-
尝试清除缓存 :delete node modules-> 然后 npm cache clean --force->npm install