2016-09-14 72 views
0

我有一個Angular2測試應用程序,它是在RC4中編寫的,工作正常。現在我想將它升級到RC7和我收到以下錯誤消息Angular2 RC7 Http模塊錯誤加載

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 

我recentActivity.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 { 
} 

我想不出什麼問題在這兒。如果我查看網絡流量,我可以看到下載的@ angular/http/index.js具有200狀態,下載的文件是預期的結果。所以我不知道爲什麼它說加載它時出錯。我還需要去哪裏看。

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); 
+0

請分享您的system.config.js – yurzui

+0

更新問題上面 –

+0

與https://github.com/alexzuza/angular2-typescript-systemjs/blob/master/systemjs.config.js另見HTTPS比較: //angular.io/docs/ts/latest/quickstart.html和https://github.com/angular/angular/blob/master/CHANGELOG.md#breaking-changes-1 – yurzui

回答

1

隨着RC.6 angular2隊釋放宣佈包配置

NPM的新的重大更改包:ESM(ES6模塊)中的代碼t現在發佈在npm包的默認位置 處,package.json的主條目 指向UMD包(主要用於節點和webpack 1用戶)。

如果您使用SystemJS來加載Angular,您應該調整您的 SystemJS配置以指向UMD軟件包(存在於npm 包中)。

請參閱此示例SystemJS config