我有react
/redux
应用程序,它运行在webpack
上,并且希望使用moment-timezone
库。我已经在这里检查了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]
}
]
发布于 2015-10-22 23:45:50
我的问题是在webpack
配置中。问题是,我需要webpack配置中的json-loader
,并将其作为对象而不是字符串传递,因此将其更改为string解决了问题:
loaders: [
{
include: /\.json$/,
loaders: ['json-loader']
}
]
https://stackoverflow.com/questions/33277602
复制相似问题