2017-01-09 3 views
2

Aureliaを使用してモジュールをロードしようとすると、私は現在、奇妙な問題に遭遇しています。私は首尾よくnpm install <module> --saveと同じ方法でnumeralライブラリを読み込もうとしていますが、モジュールライブラリではなく/distディレクトリにあるnumeralライブラリを検索しようとしていますが、日付の書式設定にはmomentライブラリを読み込んでいます。モジュールがAureliaにロードされていません


Moment使用してコード:

のsrc /フィルター/時間format.js

import moment from 'moment'; 

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

のsrc/clock.html

は、私は以下の2 ValueConvertersを持っています

<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> 

なぜそれが /distディレクトリではなく、モジュールライブラリに見えるようにしようとしている

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 

私はnumeralを使用してページを参照しようとすると、次のエラーを取得していますか?私は依存性注入にいくつかの中断があることを知っていますが、私はそれについて何をすべきか分かりません。

答えて

2

あなたはSystemJSを使用しているようです。だから、何を実行するべきことである。

jspm install numeral

あなたは非常に具体的な何かをやっている場合、あなたはSystemJSスケルトンで作業する際NPMを使用して、任意のパッケージをインストールする必要はありません場合を除き。

1

あなたはオーレリア-CLIを使用している場合は、単にaurelia_projectフォルダ内の自分のaurelia.jsonファイルに次のコードを追加します。オーレリアで

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

、あなたは常に明示的にあなたの依存関係を一覧表示するために必要としています。

スケルトンインストールを使用している場合は、Fabioの回答を参照してください。

+0

'/ dist 'について言及すると、@cchapmanはAurelia CLIを使用していない可能性があります。 –

+0

良いキャッチ。ありがとう!私の答えはCLIでのみ機能します。 – LStarky

関連する問題