2016-02-26 99 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