Skip to main content
Ben Nadel at the jQuery Conference 2010 (Boston, MA) with: Ben Alman
Ben Nadel at the jQuery Conference 2010 (Boston, MA) with: Ben Alman ( @cowboy )

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

By 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

20 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";

15,640 Comments

@Fergus,

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.

I believe in love. I believe in compassion. I believe in human rights. I believe that we can afford to give more of these gifts to the world around us because it costs us nothing to be decent and kind and understanding. And, I want you to know that when you land on this site, you are accepted for who you are, no matter how you identify, what truths you live, or whatever kind of goofy shit makes you feel alive! Rock on with your bad self!
Ben Nadel