Using instant-time with webpack

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] } ] 
+5
source share
1 answer

My problem was in webpack configurations. The problem was that I needed json-loader in the webpack configuration and passed it as an object instead of a string, so changing it to a string fixed the problem:

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

Source: https://habr.com/ru/post/1234258/


All Articles