EXCEPTION: Token must be defined!

1,257 views
Skip to first unread message

Vern Jensen

unread,
Jan 11, 2016, 10:51:00 PM1/11/16
to AngularJS
I've been working to upgrade my project from Angular Alpha 48 to the new beta.

I think I had successfully gotten alpha 52 working. Upgrading to a future version (I'm afraid I forget which... possibly alpha 53) I started getting these exceptions:

EXCEPTION: Token must be defined!
angular2.dev.js:22692 EXCEPTION: Token must be defined!BrowserDomAdapter.logError @ angular2.dev.js:22692BrowserDomAdapter.logGroup @ angular2.dev.js:22703ExceptionHandler.call @ angular2.dev.js:1163(anonymous function) @ angular2.dev.js:12545run @ angular2-polyfills.js:138(anonymous function) @ angular2.dev.js:13249NgZone.run @ angular2.dev.js:13211ApplicationRef_.bootstrap @ angular2.dev.js:12523bootstrap @ angular2.dev.js:24412(anonymous function) @ (index):89run @ angular2-polyfills.js:138zoneBoundFn @ angular2-polyfills.js:111lib$es6$promise$$internal$$tryCatch @ angular2-polyfills.js:1511lib$es6$promise$$internal$$invokeCallback @ angular2-polyfills.js:1523lib$es6$promise$$internal$$publish @ angular2-polyfills.js:1494(anonymous function) @ angular2-polyfills.js:243run @ angular2-polyfills.js:138zoneBoundFn @ angular2-polyfills.js:111lib$es6$promise$asap$$flush @ angular2-polyfills.js:1305
angular2.dev.js:22692 STACKTRACE:BrowserDomAdapter.logError @ angular2.dev.js:22692ExceptionHandler.call @ angular2.dev.js:1165(anonymous function) @ angular2.dev.js:12545run @ angular2-polyfills.js:138(anonymous function) @ angular2.dev.js:13249NgZone.run @ angular2.dev.js:13211ApplicationRef_.bootstrap @ angular2.dev.js:12523bootstrap @ angular2.dev.js:24412(anonymous function) @ (index):89run @ angular2-polyfills.js:138zoneBoundFn @ angular2-polyfills.js:111lib$es6$promise$$internal$$tryCatch @ angular2-polyfills.js:1511lib$es6$promise$$internal$$invokeCallback @ angular2-polyfills.js:1523lib$es6$promise$$internal$$publish @ angular2-polyfills.js:1494(anonymous function) @ angular2-polyfills.js:243run @ angular2-polyfills.js:138zoneBoundFn @ angular2-polyfills.js:111lib$es6$promise$asap$$flush @ angular2-polyfills.js:1305
angular2.dev.js:22692 Error: Token must be defined!
    at Array.map (native)

and nothing shows up in the webpage. 

I had switched my 'bootstrap' code to use what's in the latest example code (now done from index.html) and I figured maybe this was incompatible with the alpha version I was using, so I went ahead and tried going directly to Angular beta 1. However I still get this weird "Token must be defined" error.

I've tried debugging this further, adding console.log() calls to the angular source to see what this token is, but... it really is just an 'undefined' variable.... 

Not sure what is causing it or how to debug further. Any ideas?

Sander Elias

unread,
Jan 11, 2016, 11:17:33 PM1/11/16
to AngularJS
Hi Vern,

By now you should really update to beta-1. Better to work through the breaking changes now. 

Regards
Sander

Vern Jensen

unread,
Jan 12, 2016, 12:09:54 AM1/12/16
to ang...@googlegroups.com
Yes, that's the version I tried upgrading to, but I still get this error.

--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/D3Jk9_bCUBI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Sander Elias

unread,
Jan 12, 2016, 5:01:03 AM1/12/16
to AngularJS
Hi Vern,

line 27 of key.ts is the source of your error. It seems it is missing a injectable somewhere.

Regards
Sander

Vern Jensen

unread,
Jan 12, 2016, 5:09:41 PM1/12/16
to AngularJS
Thanks! Based on your message, I figured it was likely my bootstrapping code, which has changed since Angular alpha 48. 

I was able to get it working based on this working example here:

and by using the bootstrapping code they have, plus adding:   

to the index.html, and 
import {bootstrap} from 'angular2/platform/browser';

to the app.ts. (This is the main "key" to upgrading from alpha 48 that I was missing.)

Vern Jensen

unread,
Jan 12, 2016, 5:10:06 PM1/12/16
to AngularJS
And using the bootstrap code later in app.ts:

bootstrap(CSReportMain, [
  ROUTER_PROVIDERS,
  provide(APP_BASE_HREF, { useValue: '/' } ),
  provide(LocationStrategy, { useClass: PathLocationStrategy })
]).catch(err => console.error(err));

Reply all
Reply to author
Forward
0 new messages