Angular2 - 加载映射模块时的SystemJS 404

时间:2016-05-06 02:09:40

标签: angular systemjs

我正在我的第一个Angular2项目中工作一切正常,直到我试图从浏览器转换TS转移到构建周期的一部分进行转换。所以现在我将所有内容都转换为es5,但我错过了systemjs的内容,因为我在System.config中映射的任何内容都出现404错误,特别是angular2-jwt,这是我的config.js

System.config({
packages: {
    app: {
        defaultExtension: "js",
        main: "main"
    },
    map: {
        "angular2-jwt": "node_modules/angular2-jwt/angular2-jwt.js"
    },
    "angular2-jwt": {"defaultExtension": "js"}
}
});

这是我的切入点,main.ts

/// <reference path="../node_modules/angular2/typings/browser.d.ts" />

import {bootstrap} from 'angular2/platform/browser';
import {provide} from 'angular2/core';
import {AuthHttp, AuthConfig} from 'angular2-jwt';
import {ROUTER_PROVIDERS, LocationStrategy, HashLocationStrategy,     APP_BASE_HREF} from 'angular2/router';
import {HTTP_PROVIDERS, Http} from 'angular2/http';
import {ToastyService, ToastyConfig, Toasty} from 'ng2-toasty/ng2-toasty';

import {ApplicationComponent} from './components/application/application.component';

import {MenuService} from './services/menu/menu-service';
import {MessageService} from './services/messages/message-service';

bootstrap(ApplicationComponent, [
ROUTER_PROVIDERS,
HTTP_PROVIDERS,
ToastyService, 
ToastyConfig,
MessageService,
MenuService,
provide(AuthHttp, {
useFactory: (http) => {
  return new AuthHttp(new AuthConfig(), http);
},
deps: [Http]
}),
 provide(LocationStrategy, {useClass: HashLocationStrategy})
]);

当我尝试加载应用时,现在我得到了......

angular2-polyfills.js:126 GET http://localhost:8080/angular2-jwt 404 (Not Found)

因此浏览器正在尝试从我的导入语句路径

加载文件
import {AuthHttp, AuthConfig} from 'angular2-jwt';

而不是映射路径:

 map: {
        "angular2-jwt": "node_modules/angular2-jwt/angular2-jwt.js"
    },

在我的config.js。

我在这里缺少什么?如何让浏览器从node_modules的完整路径中提取angular2-jwt?谢谢!

1 个答案:

答案 0 :(得分:0)

map应该是packages

的兄弟姐妹
System.config({
    packages: {
        app: {
            defaultExtension: "js",
            main: "main"
        },
        "angular2-jwt": {"defaultExtension": "js"}
    },
    map: {
        "angular2-jwt": "node_modules/angular2-jwt/angular2-jwt.js"
    }
});

否则,剩下的对我来说很好看。