Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular2 exception: Token must be defined

Tags:

angular

app/boot.ts

import {bootstrap} from 'angular2/platform/browser';
import {AppComponent} from './app.component';
bootstrap(AppComponent);

app/app.component.ts

import {Component} from 'angular2/core';
@Component({
  selector: 'my-app',
  template: '{{title}}'
})
class AppComponent {
  title: "app"
}

Error:

EXCEPTION: Token must be defined!
STACKTRACE:BrowserDomAdapter.logError @ angular2.dev.js:23514
ExceptionHandler.call                 @ angular2.dev.js:1147
(anonymous function)                  @ angular2.dev.js:14801
NgZone._notifyOnError                 @ angular2.dev.js:5796
collection_1.StringMapWrapper.merge.onError @ angular2.dev.js:5700
run                                   @ angular2-polyfills.js:141
(anonymous function)                  @ angular2.dev.js:5719
NgZone.run                            @ angular2.dev.js:5681
ApplicationRef_.bootstrap             @ angular2.dev.js:14906
bootstrap                             @ angular2.dev.js:25054
execute                               @ boot.ts:4
u                                     @ system.src.js:4597
execute                               @ system.src.js:4597
y                                     @ system.src.js:4597
...
like image 688
Mark Rajcok Avatar asked Jan 02 '16 00:01

Mark Rajcok


2 Answers

This is another error that has caught me multiple times. I forgot (once again) to export my root component. It should be:

export class AppComponent {

If I taken the time to look just a bit more closely at the stack trace (instead of searching StackOverflow and not finding my exact problem), I would have noticed that it referenced one of the files I wrote, boot.ts:4.

like image 114
Mark Rajcok Avatar answered Sep 29 '22 01:09

Mark Rajcok


In my case that was just because of semi-colon at the end of following line:

import {Component} from 'angular2/core';
like image 29
Ali Sepehri.Kh Avatar answered Sep 29 '22 02:09

Ali Sepehri.Kh