【发布时间】:2016-01-21 12:42:58
【问题描述】:
我有在webpack 上运行的react/redux 应用程序,并且想使用moment-timezone 库。我已经在 SO 中检查了How should I use moment-timezone with webpack? 问题,并按照问题中的描述安装了json-loader。但仍然在我的应用程序中要求moment-timezone 时:
const momentTz = require('moment-timezone');
它引发了一个错误:
ERROR in ./~/moment-timezone/index.js
Module not found: Error: Cannot resolve 'file' or 'directory' /path-to-the-project/node_modules/moment-timezone
@ ./~/moment-timezone/index.js 2:15-51
@ ./~/moment-timezone/index.js 2:15-51 在哪里:
moment.tz.load(require('./data/packed/latest.json'));
但是,当我从构建文件夹中包含缩小版本时,它可以正常工作,如下所示:
const momentTz = require('moment-timezone/builds/moment-timezone-with-data.min');
更新:
webpack 配置:
let jsonLoader = require('json-loader');
loaders: [
{
include: /\.json$/,
loaders: [jsonLoader]
}
]
【问题讨论】:
-
那么有没有办法添加 moment-timezone 以与 moment 正确互操作,以便您可以使用 moment.tz()?
标签: node.js timezone momentjs webpack