Jeff
Jeff

Reputation: 8411

Cannot find module '@angular/platform/browser'

I have created my angular2 app using ng new myproject, and now i am going to bootstrap my app. So here is my boot.ts file:

import {bootstrap}    from '@angular/platform/browser';
import {AppComponent} from './app.component'
import {ROUTER_PROVIDERS} from '@angular/router'

bootstrap(AppComponent,[ROUTER_PROVIDERS] );

There are 2 problems in this file: in the first line '@angular/platform/browser' it complains that

Cannot find module '@angular/platform/browser'.

and in the third line import {ROUTER_PROVIDERS} from '@angular/router' it complains that:

Module '"c:/Users/Salman/Desktop/Courses/Internship/Angular2/Qminder/Qminder/node_modules/@angular/router/index"' has no exported member 'ROUTER_PROVIDERS'.

So how can i fix them? Is there anything wrong with the command ng new?

Upvotes: 2

Views: 6143

Answers (1)

Tomasz Polecki
Tomasz Polecki

Reputation: 306

As of Angular Release Candidate version 4 you should import your bootstrap function from the following module:

import { bootstrap }  from '@angular/platform-browser-dynamic';

The router module changed in the latest version of angular so you need to create "app.routes.ts" file which will have the following:

import { provideRouter, RouterConfig } from '@angular/router';

const routes: RouterConfig = [
  { path: 'home', component: HomeComponent },
  { path: '**', component: PageNotFoundComponent }
];

export const appRouterProviders = [
  provideRouter(routes)
];

Then you need to import "appRouterProviders" and provide it to the "bootstrap" method:

import { bootstrap }          from '@angular/platform-browser-dynamic';
import { AppComponent }       from './app.component';
import { appRouterProviders } from './app.routes';

bootstrap(AppComponent, [
  appRouterProviders
])
.catch(err => console.error(err));

More information about the latest router can be found here:

https://angular.io/docs/ts/latest/guide/router.html

Upvotes: 2

Related Questions