【问题标题】:Need to constantly delete node_modules for Angular 9 app to work需要不断删除 node_modules Angular 9 应用程序才能工作
【发布时间】:2020-09-07 05:58:40
【问题描述】:

我对 Web 开发非常陌生,我正在尝试熟悉构建 Angular 表单。我遇到了一个问题,每次我使用 npm startng 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

标签: node.js angular


【解决方案1】:

这似乎是 Angular 9 的重大变化。

检查这个问题:https://github.com/angular/components/issues/17503

尝试更改您的导入以使用特定组件。 例如,如果您使用的是材质按钮,则:

import { MatButtonModule } from '@angular/material/button';

【讨论】:

  • 我做了这个改变。所以那个错误消失了,但是我得到了一堆其他的错误。我会更新我的帖子。
  • 好的。你介意发布app-layer.component.ts的内容吗?从错误来看,isLinear 变量不存在。
猜你喜欢
  • 1970-01-01
  • 2013-01-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-08-13
相关资源
最近更新 更多