I have react
/redux
application that runs on webpack
and would like to use moment-timezone
library. I already checked How should I use moment-timezone with webpack? issue here in SO and installed json-loader
as it is described in the issue. But still when requiring moment-timezone
in my application as:
const momentTz = require('moment-timezone');
it raises an error:
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 the @ ./~/moment-timezone/index.js 2:15-51
is:
moment.tz.load(require('./data/packed/latest.json'));
However when I included the minified version from the build folder it worked properly, as:
const momentTz = require('moment-timezone/builds/moment-timezone-with-data.min');
webpack configs:
let jsonLoader = require('json-loader');
loaders: [
{
include: /\.json$/,
loaders: [jsonLoader]
}
]
My issue was that in the webpack
configurations. The problem was that I required the json-loader
in the webpack config and passed it as an object instead of string, so changing it to string fixed the issue:
loaders: [
{
include: /\.json$/,
loaders: ['json-loader']
}
]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With