[英]Uncaught reflect-metadata shim is required when using ES6 with Angular2 rc3
I just updated Angular from rc-1
to latest rc-3
. 我刚刚将Angular从rc-1
更新到最新的rc-3
。 The app is using JavaScript ES6 and SystemJS. 该应用程序使用的是JavaScript ES6和SystemJS。 When I run the app with browsersync, it works. 当我使用browsersync运行应用程序时,它可以工作。 But if I bundle the app (with systemjs-builder) and then run it, I have this error in the browser console 但是,如果我捆绑应用程序(使用systemjs-builder)然后运行它,我在浏览器控制台中出现此错误
Uncaught reflect-metadata shim is required when using class decorators. 使用类装饰器时,需要使用未捕获的反射元数据填充程序。
The problem comes from a component using @angular/http
with a basic http call, if I remove import {Http, HTTP_PROVIDERS} from '@angular/http' ;
问题来自使用@angular/http
和基本http调用的组件,如果我import {Http, HTTP_PROVIDERS} from '@angular/http' ;
删除import {Http, HTTP_PROVIDERS} from '@angular/http' ;
it works. 有用。
Plus, it does not happen with TypeScript but it does with JS ES5 and ES6. 此外,它不会发生在TypeScript上,但它与JS ES5和ES6一起发生。 Also it doesn't happen with Webpack. Webpack也不会发生这种情况。
I looked into the bundled code and it appears that SystemJS goes through Angular
code before Reflect
code... only with es6 我查看了捆绑的代码,看起来SystemJS在Reflect
代码之前通过Angular
代码...仅使用es6
index.js index.js
import 'reflect-metadata';
import 'es6-shim';
import 'zone.js';
import {bootstrap} from '@angular/platform-browser-dynamic';
import {App} from './app.js';
bootstrap(App);
app.js app.js
import {Component} from '@angular/core';
import {Http, HTTP_PROVIDERS} from '@angular/http';
@Component({
selector: 'App',
template: '',
providers: [HTTP_PROVIDERS]
})
export class App {
constructor(http) {}
static get parameters() {
return [[Http]];
}
}
reflect-metadata
, es6-shim
and zone.js
are supposed to be global libraries. reflect-metadata
, es6-shim
和zone.js
应该是全局库。 Consequently, you should not import them into one of your modules like you do in index.js. 因此,您不应像在index.js中那样将它们导入到其中一个模块中。
Try removing the import statements in your index.js and reference them in your index.html like it is explained in the Angular 2 Quickstart : 尝试删除index.js中的import语句并在index.html中引用它们,就像Angular 2快速入门中所述 :
<script src="node_modules/zone.js/dist/zone.js"></script>
<script src="node_modules/reflect-metadata/Reflect.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.