Skip to main content
Ben Nadel
On User Experience (UX) Design, JavaScript, ColdFusion, Node.js, Life, and Love.

EXCEPTION: Token Must Be Defined! In Angular 2 Beta 1

By Ben Nadel on

Apparently, this was a good week to trip over a lot of cryptic Angular 2 Beta 1 error messages. On the tails of my last post, about "No provider for ParamDecorator" errors, I tripped over another parameter-related error. This time, I was accidentally referring to an undefined value in my Inject() metadata constructor:

WidgetComponent.parameters = [ new ng.core.Inject( ng.core.NgModel ) ];

... which resulted in the following error:

EXCEPTION: Token must be defined!

This is a particularly dubios error as the message doesn't indicate any relation to dependency-injection and the stack trace doesn't point to any particular part of the code. Luckily, it was only a small demo and I was able to narrow it down to the NgModel reference, which should have been in the "common" module:

WidgetComponent.parameters = [ new ng.core.Inject( ng.common.NgModel ) ];

This might not be an error you ever see if you're using ES6 modules. But, I figured it might be worth documenting since its a somewhat unhelpful error message.

Reader Comments

> This might not be an error you ever see if you're using ES6 modules.

If one were to reference NgModel directly, one still needs to import it from the right place

import {NgModel} from "angular2/common";


Ah, very true. I haven't used ES6 yet (except in the Getting Started Guide). I guess I assumed it might throw a more meaningful error. But maybe it just shows up as undefined all the same.