Angular2 decorators are not defined

3k Views Asked by At

My project builds with webpack but when I host the app from localhost I get an error.

Uncaught ReferenceError: __decorate is not defined.

Initially i get the error with the Injectable() decorator. But when I uncomment that I get the same error but with extends.

Ive created a repo that duplicates the errors.
https://github.com/shawnrmoss/decorators

I suspect it has something to do with typings since the problem started when I had to change those definitions.
typings_orig.json has the original typings definitions

Im no sure what is going on. Hopefully someone can shine a light on this and help me out.

Thanks.

1

There are 1 best solutions below

1
On BEST ANSWER

I think you don't import include the Reflect-metadata library into your project. This library is provided by Angular thanks to the angular2-polyfills.js file. This library contains both ZoneJS and Reflect-metadata.

This library is used by decorators, specially the @Injectable one. They internally use the Reflect.decorate function.

From your comment, it seems that you only import es6-promise and zone-microtask...

I started with the angularclass starter kit. In the vendor ts file it has this // (these modules are what are in 'angular2/bundles/angular2-polyfills' so don't use that here) import 'es6-promise'; import 'zone.js/lib/browser/zone-microtask';

This article could help you and look for Reflect.decorate: