2

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.

smoss
  • 39
  • 1
  • 9
  • Could you give us more details about what you use? ES5, ES6, TypeScript? – Thierry Templier Feb 26 '16 at 16:35
  • Sure: angular 2 2.0.0.0-beta.0, typescript 1.7.5, es6 – smoss Feb 26 '16 at 16:37
  • Uncaught ReferenceError: __decorate is not defined(anonymous function) @ auth.service.ts:6(anonymous function) @ auth.service.ts:87__webpack_require__ @ bootstrap 435ddfde67fa15c11a9e:50(anonymous function) @ main.ts:1__webpack_require__ @ bootstrap 435ddfde67fa15c11a9e:50webpackJsonpCallback @ bootstrap 435ddfde67fa15c11a9e:21(anonymous function) @ main.bundle.js:1 – smoss Feb 26 '16 at 16:39
  • Everything was working fine. Then I had a hard drive fail. Had to download the project from our repository and reinstall the node_modules. Since then I get this error – smoss Feb 26 '16 at 16:42
  • Thanks! Did you include the `angular2-polyfills.js` file? – Thierry Templier Feb 26 '16 at 16:42
  • 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'; – smoss Feb 26 '16 at 16:44
  • `decorate` makes me thing about a problem at the reflect-metadata library (see `Reflect.decorate`) which is contained into `angular2-polyfills.js`... That's why I asked you for – Thierry Templier Feb 26 '16 at 16:46
  • That starter kit is horrible. It is like starting off with a sizable legacy code base and 10 years if technical dept with horrible practices ingrained instead of starting a brand new project. – Aluan Haddad Dec 19 '16 at 03:33

1 Answers1

-1

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:

Thierry Templier
  • 198,364
  • 44
  • 396
  • 360
  • Thank you so much for your help. I read through the article you provided but Im still at a loss. I create a stripped down repo that duplicates the error Im getting https://github.com/shawnrmoss/decorators.git – smoss Feb 26 '16 at 18:51