Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular2: ngModule, BrowserModule, FormsModule are not exported members

Tags:

angular

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?

like image 324
beewest Avatar asked Aug 10 '16 03:08

beewest


People also ask

What kind of components can be included in exports of NgModule?

An NgModule can export a combination of its own declarations, selected imported classes, and imported NgModules. Don't bother re-exporting pure service modules. Pure service modules don't export declarable classes that another NgModule could use.

What should be imported BrowserModule or CommonModule?

Only root application module, AppModule , should import BrowserModule and all other feature module should import CommonModule because we only need the Angular directives in feature module and not the services that are required to launch the app(Which are already available in RootModule).

Which angular module is needed for NGLF ngFor?

BrowserModule and CommonModule link BrowserModule imports CommonModule , which contributes many common directives such as ngIf and ngFor .


2 Answers

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!

like image 155
MW. Avatar answered Oct 07 '22 09:10

MW.


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

like image 42
Kim Phung Avatar answered Oct 07 '22 10:10

Kim Phung