简体   繁体   English

Angular 2 RC6错误:ReferenceError:未定义$ traceurRuntime

[英]Angular 2 RC6 Error: ReferenceError: $traceurRuntime is not defined

I am updating rc5 project to rc6. 我正在将rc5项目更新为rc6。 When I serve the project, I am getting Error: ReferenceError: $traceurRuntime is not defined . 服务项目时,出现Error: ReferenceError: $traceurRuntime is not defined I do not even know what is wrong. 我什至不知道出什么问题了。 My system.config.js looks as following: 我的system.config.js如下所示:

(function (global) {
  var map = {
    'app': 'app'
  };
  var packages = {
    'app': { main: 'main.js', defaultExtension: 'js' },
    'rxjs': { defaultExtension: 'js' },
  };
  var ngPackageNames = [
    'common',
    'compiler',
    'core',
    'forms',
    'http',
    'platform-browser',
    'platform-browser-dynamic',
    'router'
  ];
  // Add package entries for angular packages
  ngPackageNames.forEach(function packIndex(pkgName) {
    packages['@angular/' + pkgName] = { main: 'index.js', defaultExtension: 'js' };
  });

  System.config({
    defaultJSExtensions: true,
    map: map,
    packages: packages
  });
})(this);

index.html as following: index.html如下:

<!DOCTYPE html>
<html lang="en">

<head>
  <base href="/">
  <title>Angular2 rc6</title>
  <meta name="viewport" content="width=device-width, initial-scale=1">

  <link rel="stylesheet" type="text/css" href="../node_modules/bootstrap/dist/css/bootstrap.min.css" />
  <!-- endbuild -->

  <!-- build:js lib/core.js -->
  <script src="../node_modules/core-js/client/shim.min.js"></script>
  <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>
  <!-- endbuild -->
  <!-- dependencies  -->
  <script src="lib/dependencies.bundle.js"></script>

  <!-- build:js lib/dependencies.bundle.js 
  <script src="../node_modules/rxjs/bundles/Rx.js"></script>
  <script src="../node_modules/@angular/common/bundles/common.umd.js"></script>
  <script src="../node_modules/@angular/compiler/bundles/compiler.umd.js"></script>
  <script src="../node_modules/@angular/core/bundles/core.umd.js"></script>
  <script src="../node_modules/@angular/forms/bundles/forms.umd.js"></script>
  <script src="../node_modules/@angular/http/bundles/http.umd.js"></script>
  <script src="../node_modules/@angular/platform-browser/bundles/platform-browser.umd.js"></script>
  <script src="../node_modules/@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js"></script>
  <script src="../node_modules/@angular/router/bundles/router.umd.js"></script>
  -->
  <!-- endbuild -->

  <!-- 2. Configure SystemJS -->
  <script src="systemjs.config.js"></script>
  <script>
    System.import('app/main').catch(function(err){ console.error(err); });
  </script>
</head>

<body>
  <app>Loading...</app>
</body>

</html>

I assume this is issue is somehow systemjs related, but cannot figure out what am I really doing wrong? 我认为这是与systemjs相关的问题,但无法弄清楚我到底在做什么错?

Edit: I have found that the problem is in dependencies.bundle.js, that I am generating for dependencies bundle. 编辑:我发现问题出在我为依赖项捆绑包生成的dependencies.bundle.js中。

 System.register("@angular/http/src/static_request.js", ["@angular/http/src/facade/lang.js", "@angular/http/src/body.js", "@angular/http/src/enums.js", "@angular/http/src/headers.js", "@angular/http/src/http_utils.js", "@angular/http/src/url_search_params.js"], function($__export) {
      "use strict";
...
w = (typeof window === 'undefined' ? 'undefined' : $traceurRuntime.typeof(window)) == 'object' ? window : noop;

Since RC6 it looks like you now have to use the UMD bundles if using SystemJS to load Angular. 从RC6开始,如果使用SystemJS加载Angular,现在看起来您必须使用UMD捆绑软件。

From the Changelog 变更日志

npm packages: code in ESM (ES6 Modules) format is now published at the default location in the npm package with package.json's main entry pointing to an UMD bundle (primarily for node, and webpack 1 users). npm软件包:ESM(ES6模块)格式的代码现已发布在npm软件包的默认位置,其中package.json的主条目指向UMD软件包(主要用于节点和webpack 1用户)。

If you are using SystemJS to load Angular, you should adjust your SystemJS configuration to point to the UMD bundles (present in the npm package). 如果使用SystemJS加载Angular,则应调整SystemJS配置以指向UMD捆绑包(在npm软件包中)。

Please see this example SystemJS config . 请参阅此示例SystemJS config

I'm using SystemJS Builder and this change has given me some serious problems that I need to sort out. 我正在使用SystemJS Builder,此更改使我遇到了一些严重的问题,需要解决。

SystemJs use traucer as default transpiler, somehow adding: SystemJs使用traucer作为默认编译器,以某种方式添加:

transpiler: false 转译器:假

to my systemjs config resolved this issue for me. 我的systemjs配置为我解决了这个问题。

Reference: https://github.com/systemjs/systemjs/blob/master/docs/config-api.md#transpiler 参考: https : //github.com/systemjs/systemjs/blob/master/docs/config-api.md#transpiler

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM