2016-02-26 94 views
1

我的項目使用webpack構建,但是當我從localhost託管應用程序時,出現錯誤。Angular2裝飾器未定義

未捕獲ReferenceError:__decorate未定義。

最初我得到了Injectable()裝飾器的錯誤。但是當我取消註釋時,我得到了相同的錯誤,但延伸。

我創建了一個複製錯誤的倉庫。
https://github.com/shawnrmoss/decorators

我懷疑它與類型有關,因爲當我必須改變這些定義時問題就開始了。
typings_orig.json有原始的類型定義

我不知道發生了什麼事。希望有人能夠照亮這一點並幫助我。

謝謝。

+0

您能否介紹一下您使用的更多細節? ES5,ES6,TypeScript? –

+0

當然: 角2 2.0.0.0-beta.0,typescript 1.7.5,es6 – smoss

+0

未捕獲的ReferenceError:__decorate未定義(匿名函數)@ auth.service.ts:6(匿名函數)@ auth.service.ts :87__webpack_require__ @ bootstrap 435ddfde67fa15c11a9e:50(匿名函數)@main.ts:1__webpack_require__ @bootstrap 435ddfde67fa15c11a9e:50webpackJsonpCallback @bootstrap 435ddfde67fa15c11a9e:21(匿名函數)@main.bundle.js:1 – smoss

回答

0

我認爲你不要將Reflect-metadata庫導入到你的項目中。這個庫由Angular提供,感謝angular2-polyfills.js文件。這個庫包含ZoneJS和反射元數據。

這個庫正被裝飾者使用,特別是@Injectable之一。它們在內部使用Reflect.decorate函數。

從您的評論,似乎你只進口ES6-承諾,區,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';

這篇文章可以幫助你查找Reflect.decorate

+0

非常感謝您的幫助。我讀過你提供的文章,但我仍然無所適從。我創建了一個精簡的repo,它重複了錯誤我正在獲取https://github.com/shawnrmoss/decorators.git – smoss