【发布时间】:2019-10-05 01:10:09
【问题描述】:
尽管遵循此处的建议 -- TypeScript error in Angular2 code: Cannot find name 'module',但我仍然收到此错误。我正在使用 Angular 5 和 npm 6.9.0。我正在尝试在这里完成本教程——https://medium.freecodecamp.org/learn-how-to-create-your-first-angular-app-in-20-min-146201d9b5a7。
我的 ./src/app/app.component.ts 文件顶部有这个
import { Component,trigger,animate,style,transition,keyframes } from '@angular/core';
import { FormsModule } from '@angular/forms';
@NgModule({
imports: [
BrowserModule,
FormsModule //<----------make sure you have added this.
],
})
但是当我运行我的应用程序时,我得到了错误
localhost:todo-app davea$ ng serve
** NG Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
Date: 2019-05-17T17:06:29.377Z
Hash: e9b5158cd1cb6d5685c7
Time: 2561ms
chunk {inline} inline.bundle.js (inline) 3.85 kB [entry] [rendered]
chunk {main} main.bundle.js (main) 2.91 kB [initial] [rendered]
chunk {polyfills} polyfills.bundle.js (polyfills) 577 bytes [initial] [rendered]
chunk {styles} styles.bundle.js (styles) 41.6 kB [initial] [rendered]
chunk {vendor} vendor.bundle.js (vendor) 867 kB [initial] [rendered]
ERROR in src/app/app.component.ts(4,2): error TS2552: Cannot find name 'NgModule'. Did you mean 'module'?
src/app/app.component.ts(6,14): error TS2304: Cannot find name 'BrowserModule'.
我还需要做什么才能让 NgModule 被识别?
【问题讨论】:
-
如果上面的代码是你最终得到的,那么你要么没有足够仔细地遵循教程,要么教程是垃圾。我认为是前者。
-
你需要从
@angular/core导入NgModule。 -
@pjlamb12,将第一行更改为“import { Component,NgModule,trigger,animate,style,transition,keyframes } from '@angular/core';”确实有效。
标签: angular typescript npm node-modules