2016-05-06 107 views
3

我在我的第一個Angular2項目中工作一切正常,直到我試圖從瀏覽器transpiling TS轉移到作爲構建週期一部分的transpiling。所以現在我把所有東西都轉換成es5,但是我缺少一些與systemjs相關的東西,因爲我在我的System.config中映射的任何東西上都有404錯誤,具體是angular2-jwt,這裏是我的config.jsAngular2 - SystemJS 404當加載映射模塊

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?謝謝!

回答

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" 
    } 
}); 

兄弟,否則,剩下對我來說很好。

+0

哇,謝謝!我只是看了20個其他的配置文件,並沒有注意到! – csyperski

+0

不客氣@csyperski,這只是我犯了同樣的錯誤夫婦之前:) – Abdulrahman

+0

這是在index.html?它怎麼可能將node_modules代碼捆綁到Web服務器中? –