I have a react / redux application that runs on webpack and wants to use the moment-timezone library. I already checked How to use a point in time with webpack? here in SO and install json-loader as described in this problem. But when using moment-timezone in my application:
const momentTz = require('moment-timezone');
an error occurs:
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
Where @ ./~/moment-timezone/index.js 2:15-51 :
moment.tz.load(require('./data/packed/latest.json'));
However, when I included the mini version from the build folder, it worked correctly:
const momentTz = require('moment-timezone/builds/moment-timezone-with-data.min');
Update:
Webpack configurations:
let jsonLoader = require('json-loader'); loaders: [ { include: /\.json$/, loaders: [jsonLoader] } ]
source share