15

Error message

VM556 angular2-polyfills.js:349Error: Token must be defined!(…)

or

error TS2305: Module '"/node_modules/angular2/router"' has no exported member 'LocationStrategy'.
error TS2305: Module '"/node_modules/angular2/router"' has no exported member 'HashLocationStrategy'.
error TS2305: Module '"/node_modules/angular2/router"' has no exported member 'Location'.

How to fix

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567

1 Answers1

30

update >= rc.5

@NgModule({
  providers: [{ provide: LocationStrategy, useClass: HashLocationStrategy}]
})
export class AppModule {}

update >= rc.0

import {  
  PlatformLocation,  
  Location,  
  LocationStrategy,  
  HashLocationStrategy,  
  PathLocationStrategy,  
  APP_BASE_HREF}  
from '@angular/common';  

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

original

Change

import {ROUTER_PROVIDERS, LocationStrategy, HashLocationStrategy} from 'angular2/router';

to

import {ROUTER_PROVIDERS} from 'angular2/router';
import {LocationStrategy, HashLocationStrategy} from 'angular2/platform/common';

See also
- https://github.com/angular/angular/issues/8229

Full list of moved exports:
- https://github.com/angular/angular/pull/8230/files

import {  
  PlatformLocation,  
  Location,  
  LocationStrategy,  
  HashLocationStrategy,  
  PathLocationStrategy,  
  APP_BASE_HREF}  
from 'angular2/platform/common';  

import {BrowserPlatformLocation} from   'angular2/src/platform/browser/location/browser_platform_location';

Another error that's commonly caused by this change is

location.createComponent is not a function

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
  • 4
    basically `LocationStrategy` & `HashLocationStrategy` have been moved out to `angular2/platform/common` module, could you add this in your answer, so that would be more informative :) – Pankaj Parkar Apr 26 '16 at 10:16
  • as for people who are saying this is old please follow below link http://blog.ng-book.com/basic-routing-in-angular-2/ – Kamran Pervaiz Aug 04 '16 at 10:02