【问题标题】:Angular2 RC1 loading issue - SyntaxError: Unexpected token <Angular2 RC1 加载问题 - SyntaxError: Unexpected token <
【发布时间】:2016-06-13 15:03:47
【问题描述】:

我正在尝试将我的应用程序从 Angular 2 beta 18 更新到 Angular2 RC1,我已经更改了导入,修复了很多语法错误,现在,我在加载应用程序时收到此错误。 Angular2 快速入门也不起作用!

zone.js:323 Error: (SystemJS) SyntaxError: Unexpected token <
    Evaluating http://localhost:8080/@angular/platform-browser-dynamic
    Error loading http://localhost:8080/app/ts/main.component.js

我的主要组件是:

import {bootstrap} from '@angular/platform-browser-dynamic';
import {AppComponent} from './app.component';

bootstrap(AppComponent);

我找到了这个 https://github.com/valor-software/ng2-dragula/issues/274,但我不知道它是什么意思,在哪里搜索 require 等等。谢谢。

【问题讨论】:

    标签: angular


    【解决方案1】:

    您必须向您的模块加载器 (SystemJS) 描述您的应用程序的结构,以便它在解析您的导入时知道在哪里查找文件。现在它在app/ts/ 文件夹中查找main.component.js,并且您的服务器返回SystemJS 无法理解的默认文件(可能是index.html)(index.html 中的第一个字符是&lt;)。

    要配置 SystemJS,请将 map 和/或 packages 属性添加到 system-config.js 中的 config 对象

    System.config({
      map: { 
        // when I ask for 'app' look for it in 'path/to/app` folder
        app: 'path/to/app' 
      },
      // describe 'app' package, so System knows how to handle it
      // look at docs for options...
      packages: { 
        app: {
          // if you compiled ts to CommonJS module
          format: 'cjs'
        }
      },
    });
    

    我建议您查看一些工作应用的示例,了解它们是如何配置的,或者使用为您处理配置的工具,例如 Angular CLI

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-05
      • 2020-01-25
      • 2017-04-01
      • 1970-01-01
      相关资源
      最近更新 更多