简体   繁体   English

将ES6与Angular2 rc3一起使用时,需要使用未捕获的反射元数据填充程序

[英]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-metadataes6-shimzone.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.

相关问题 Natviescript中的单元测试Angular:使用类装饰器时需要reflect-metadata shim - Unit Testing Angular in Natviescript: reflect-metadata shim is required when using class decorators Angular2 RC-4迁移失败,带有反射元数据 - Angular2 RC-4 migration failing with reflect-metadata Angular2使用npm reflect-metadata或core-js / es7 / reflect - Angular2 using either npm reflect-metadata or core-js/es7/reflect Angular2无法更新到RC7-zone.js和reflect-metadata - Angular2 Failing to update to RC7 - zone.js & reflect-metadata 如何使用Reactive Forms(Angular2 RC3)进行异步验证? - How to do asynchronous validation with Reactive Forms (Angular2 RC3)? 使用类装饰器(节点)时,需要relect-metadata填充程序 - relect-metadata shim is required when using class decorators (node) SharePoint Framework中的反射元数据突然中断 - Reflect-metadata suddenly breaking in Sharepoint Framework 如何使用Angular 2(beta和更新版本)加载RxJS(和zone.js / reflect-metadata)? - How to load RxJS (and zone.js / reflect-metadata) with Angular 2 (beta and newer)? 在IE中运行Angular 5应用程序,而无需使用“导入&#39;core-js / es6 / reflect&#39;和导入&#39;core-js / es7 / reflect&#39;” - Run Angular 5 app in IE without using “import 'core-js/es6/reflect' and import 'core-js/es7/reflect'” 在方法中使用“ for of”时,ES6类中的“未捕获引用”错误 - “Uncaught reference” error in ES6 class when using `for of` in method
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM