We are also using with babel-loader for the same through webpack but problem still exists.
webpack server config
var webpack = require('webpack');
//var path = require('path');
//const nodeExternals = require('webpack-node-externals');
const getClientEnvironment = require('./env');
const paths = require('./paths');
const publicPath = paths.servedPath;
const publicUrl = publicPath.slice(0, -1);
const env = getClientEnvironment(publicUrl);
env.stringified = {...env.stringified,'isClientEnv':JSON.stringify(false)};
var LodashModuleReplacementPlugin = require('lodash-webpack-plugin');
const config = {
entry: {
server: paths.serverIndexJs,
},
output: {
filename: '[name].bundle.dev.js',
path: paths.serverBuildPath,
chunkFilename: '[name].[chunkhash].js'
},
mode : env.raw.NODE_ENV,
target : 'node',
// externals: [nodeExternals()],
resolve: {
modules: ['node_modules', 'src'],
extensions: ['*', '.js', '.json']
},
module: {
rules: [
// {
// test: [/.bmp$/, /.gif$/, /.jpe?g$/, /.png$/],
// loader: require.resolve('url-loader'),
// options: {
// limit: 10000,
// name: 'static/media/[name].[hash:8].[ext]',
// },
// },
{
test: /.(jsx|js)?$/,
exclude: /(node_modules/)/,
use: {
loader: "babel-loader"
}
},
{
test: /\.css$/,
use: [
{
loader: "css-loader/locals"
}
]
}
],
},
plugins: [
new webpack.DefinePlugin(env.stringified),
new LodashModuleReplacementPlugin
]
};
module.exports = config;