Angular2 - 加载映射模块时出现 SystemJS 404

标签 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 语句路径加载文件

import {AuthHttp, AuthConfig} from 'angular2-jwt';

而不是映射路径:

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

在我的 config.js 中。

我在这里错过了什么?如何让浏览器从 node_modules 的完整路径中拉取 angular2-jwt?谢谢!

最佳答案

map 应该是 packages

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

否则,其余的我觉得不错。

关于Angular2 - 加载映射模块时出现 SystemJS 404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37063134/

相关文章:

javascript - Angular 2 中的 System.import 总是尝试从 url 导入

javascript - Angular2/Typescript 知道何时获取了 http 或更新了一个 observable

angular - 用于 Angular 2 应用程序的 SystemJS 与 Webpack

javascript - 为什么导入js文件时需要.js扩展名

file-upload - Angular 2 : ng2-file-upload : cannot load it correctly using SystemJS

javascript - systemjs - 如果文件包含 "system.import",则 "use strict"失败

html - 如何显示和隐藏由 Angular 2 中的动态按钮触发的动态 div

javascript - 嵌套订阅并需要所有值作为正文传递给 API - Angular 6 RxJS

angular - ng2-tel-输入 : Country flag do not change automatically when manually change input

javascript - 找出渲染项目的时间