2017-01-09 164 views
2

當我嘗試加載Aurelia模塊時,我正遇到一個奇怪的問題。我已經成功加載moment庫來格式化日期,但是我試圖加載numeral庫與npm install <module> --save完全相同,但它試圖在/dist目錄中找到numeral庫,而不是模塊庫。模塊未加載Aurelia

我有空兩個ValueConverters:


使用Moment代碼:

的src /過濾/時間format.js

import moment from 'moment'; 

export class TimeFormatValueConverter { 
    toView(value) { 
    return moment(value).format('h:mm'); 
    } 
} 

的src/clock.html

<template> 
    <require from="./filters/date-format"></require> 
    <require from="./filters/time-format"></require> 
    <section class="au-animate"> 
    <h2 class="clock-font-large">${time | timeFormat}</h2> 
    </section> 
</template> 

代碼試圖利用Numeral

的src /過濾器/溫度format.js

import numeral from 'numeral'; 

export class TemperatureFormatValueConverter { 
    toView(value) { 
    return numeral(value).format('(00)'); 
    } 
} 

的src/weather.html

<template> 
    <require from="./filters/temperature-format"></require> 
    <section class="au-animate"> 
    <h2 class="clock-font-large">${weather.main.temp | temperatureFormat }</h2> 
    </section> 
</template> 

我越來越想看看使用numeral頁面時出現以下錯誤:

ERROR [app-router] Error: (SystemJS) XHR error (404 Not Found) loading http://clock.localhost:9000/dist/numeral.js 
    Error: XHR error (404 Not Found) loading http://clock.localhost:9000/dist/numeral.js 
    Error loading http://clock.localhost:9000/dist/numeral.js as "numeral" from http://clock.localhost:9000/dist/filters/temperature-format.js 

爲什麼試圖在/dist目錄,而不是模塊庫看?我知道依賴注入有一些中斷,但我不知道該怎麼做。

回答

2

看來你正在使用SystemJS。所以,你應該運行是:

jspm install numeral

除非你正在做的事情非常具體的,您不必安裝與SystemJS骷髏工作時使用NPM的軟件包。

1

如果您使用Aurelia大街,CLI,只需將下面的代碼添加到您的aurelia.json文件中的文件夾aurelia_project

   { 
        "name": "numeral", 
        "path": "../node_modules/numeral", 
        "main": "numeral" 
       }, 

在Aurelia路上,你總是需要明確地列出你的依賴。

如果您使用Skeleton安裝,請參閱Fabio的答案。

+0

鑑於提及'/ dist',@ cchapman不太可能使用Aurelia CLI。 –

+0

好的。謝謝!我的答案只適用於CLI。 – LStarky