【发布时间】:2017-05-24 01:17:30
【问题描述】:
我目前在尝试使用 Aurelia 加载模块时遇到了一个奇怪的问题。我已经成功加载了moment 库以格式化日期,但是我试图以与npm install <module> --save 完全相同的方式加载numeral 库,但它试图在/dist 中找到numeral 库目录而不是模块库。
我在下面有两个 ValueConverter:
使用Moment的代码:
src/filters/time-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/filters/temperature-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 目录而不是模块库?我知道依赖注入有一些中断,但我不知道该怎么办。
【问题讨论】:
标签: javascript npm aurelia