Angular2 RC7 Http模块错误加载

保罗·卡瓦卡斯

我有一个用RC4编写的Angular2测试应用程序,效果很好。我现在正尝试将其升级到RC7,并且收到以下错误消息

Error: SyntaxError: Unexpected token <
    Evaluating http://localhost:7864/traceur
    Error loading http://localhost:7864/traceur
    Error loading http://localhost:7864/libs/@angular/http/index.js as "@angular/http" from http://localhost:7864/app/recentActivity/recentActivity.module.js

我的最近的Activity.module看起来像这样:

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { HttpModule } from '@angular/http';

import { RecentActivityService } from './recentActivity.service';
import { RecentActivityComponent } from './recentActivity.component';

@NgModule({
    imports: [CommonModule, HttpModule],
    declarations: [RecentActivityComponent],
    exports: [RecentActivityComponent],
    providers: [RecentActivityService]
})
export class RecentActivityModule {
}

我不知道这里出了什么问题。如果查看网络流量,可以看到下载状态为200的@ angular / http / index.js,下载的文件是预期的结果。因此,我不知道为什么会说加载它时出错。我还需要去哪里看看。

systemjs.config在下面

/**
 * System configuration for Angular 2 samples
 * Adjust as necessary for your application needs.
 */
(function () {
    // map tells the System loader where to look for things
    var map = {
        'app': 'app', // 'dist',
        '@angular': 'libs/@angular',
        'angular2-in-memory-web-api': 'libs/angular2-in-memory-web-api',
        'rxjs': 'libs/rxjs'
    };
    // packages tells the System loader how to load when no filename and/or no extension
    var packages = {
        'app': { main: 'main.js', defaultExtension: 'js' },
        'rxjs': { defaultExtension: 'js' },
        'angular2-in-memory-web-api': { main: 'index.js', defaultExtension: 'js' }
    };
    var ngPackageNames = [
      'common',
      'compiler',
      'core',
      'forms',
      'http',
      'platform-browser',
      'platform-browser-dynamic',
      'router',
      'router-deprecated',
      'upgrade'
    ];

    var ngIndexPackageNames = [
   'http'
    ];
    // Individual files (~300 requests):
    function packIndex(pkgName) {
        packages['@angular/' + pkgName] = { main: 'index.js', defaultExtension: 'js' };
    }
    // Bundled (~40 requests):
    function packUmd(pkgName) {
        packages['@angular/' + pkgName] = { main: '/bundles/' + pkgName + '.umd.js', defaultExtension: 'js' };
    }
    // Most environments should use UMD; some (Karma) need the individual index files
    var setPackageConfig = System.packageWithIndex ? packIndex : packUmd;
    // Add package entries for angular packages
    ngPackageNames.forEach(setPackageConfig);
    ngIndexPackageNames.forEach(packIndex);
    var config = {
        //meta: {
        //    '*.js': {
        //        scriptLoad:true
        //    }
        //},
        map: map,
        packages: packages
    };
    System.config(config);
})(this);
yurzui

随着RC.6的发布,angular2团队宣布了软件包配置方面新突破性变化

npm软件包:ESM(ES6模块)格式的代码现已发布在npm软件包的默认位置,其中package.json的主条目指向UMD软件包(主要用于节点和webpack 1用户)。

如果使用SystemJS加载Angular,则应调整SystemJS配置以指向UMD捆绑包(在npm软件包中)。

请参阅此示例SystemJS config

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章