5

Despite following the advice here -- TypeScript error in Angular2 code: Cannot find name 'module', I'm still getting this error. I'm using Angular 5 and npm 6.9.0. I'm trying to work through this tutorial here -- https://medium.freecodecamp.org/learn-how-to-create-your-first-angular-app-in-20-min-146201d9b5a7 .

I have this at the top of my ./src/app/app.component.ts file

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.
           ],
})

But when I run my application I get the error

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'.

What else do I need to do to get NgModule recognized?

R. Richards
  • 24,603
  • 10
  • 64
  • 64
Dave
  • 15,639
  • 133
  • 442
  • 830
  • If the code above is what you ended up with, then you either didn't follow the tutorial closely enough, or the tutorial is junk. I think it's the former. – R. Richards May 17 '19 at 17:18
  • You need to import `NgModule` from `@angular/core`. – pjlamb12 May 17 '19 at 18:17
  • @pjlamb12, Changing the first line to "import { Component,NgModule,trigger,animate,style,transition,keyframes } from '@angular/core';" did indeed work. – Dave May 17 '19 at 19:00

1 Answers1

8

This error, Cannot find name 'NgModule', is due to not having imported NgModule from @angular/core. Adding that to the first line will solve the issue.

pjlamb12
  • 2,300
  • 2
  • 32
  • 64