我在我的第一个 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/