beewest
beewest

Reputation: 4846

Angular2: ngModule, BrowserModule, FormsModule are not exported members

I am going through the Angular2 tutorial at https://angular.io/docs/ts/latest/tutorial/toh-pt5.html. All good to step Routing. Visual Studio Code shows the error at first 03 lines:

import { NgModule }       from '@angular/core';
import { BrowserModule }  from '@angular/platform-browser';
import { FormsModule }    from '@angular/forms';

as

[ts] 
Module '"c:/Users/ktran/Source/Repos/angular2-quickstart-ts/node_modules/@angular/core/index"' has no exported member 'NgModule'.

folder node_modules:

enter image description here

any idea please?

Upvotes: 29

Views: 50743

Answers (7)

jay rangras
jay rangras

Reputation: 144

You must import this symbol in the module file. I am pretty sure that you are importing it in the component file.

Upvotes: 0

uday
uday

Reputation: 11

if you have this type of error. import { NgModule} from '@angular/core'; import {BrowserModule} from '@angular/platform-browser'; try this command:

npm update

Upvotes: 1

Kim Phung
Kim Phung

Reputation: 152

Some modules just get added to the new version of Angular, so if you are not updating, you can not import it.

After about half an hour of search, got a solution:

Create a new folder and cd to your folder.

In command line, Type:

 git clone  https://github.com/angular/quickstart
 cd quickstart
 npm install

And copy your old code to the newly created project

Upvotes: 11

john Smith
john Smith

Reputation: 1605

Please make sure you have included the FormsModule to the ngModule imports

@NgModule({
    imports:      [ BrowserModule,**FormsModule** ],
    declarations: [ AppComponent ],
    bootstrap:    [ AppComponent ]
})

Upvotes: 0

Dias Abdraimov
Dias Abdraimov

Reputation: 1077

If this solutions didn't help you, try to reopen VSCode. For me it was editor issue.

Upvotes: 12

Sebastian Castaldi
Sebastian Castaldi

Reputation: 9004

I just had a similar issue upgrading a sample app to 2.0.1 using the quickstart sample. I fixed it by updating not only the package.json, but also systemjs.config.js and typings.json

Upvotes: 0

MW.
MW.

Reputation: 12630

As Kim Phung stated, this is because a new RC of Angular was just released. Change the following lines in packages.json:

// ...snip...
"dependencies": {
    "@angular/common": "2.0.0-rc.5",
    "@angular/compiler": "2.0.0-rc.5",
    "@angular/core": "2.0.0-rc.5",
    "@angular/forms": "0.3.0",
    "@angular/http": "2.0.0-rc.5",
    "@angular/platform-browser": "2.0.0-rc.5",
    "@angular/platform-browser-dynamic": "2.0.0-rc.5",

// ...file continues...

Then run, in your console:

npm update

Good to go!

Upvotes: 32

Related Questions