使用webpack的时刻

我有react / redux应用程序运行在webpack并希望使用moment-timezone库。 我已经检查过我应该如何使用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'); 

更新:

webpackconfiguration:

 let jsonLoader = require('json-loader'); loaders: [ { include: /\.json$/, loaders: [jsonLoader] } ] 

我的问题是在webpackconfiguration。 问题是我需要在webpackconfigurationjson-loader ,并将其作为一个对象而不是string,所以将其更改为string修复问题:

 loaders: [ { include: /\.json$/, loaders: ['json-loader'] } ]