support for webpack 5
See original GitHub issueIt seems that webpack 5 in production mode breaks the singleton mode (that was working fine for webpack 4). It throws an error that __webpack_exports__ is not defined
. In development mode for webpack 5 everything works as expected, but only in production it generates the error. I identified that if I set in webpack optimization usedExports: false
then the issue is resolved (however that is an undesirable option).
This is the config for webpack:
module.exports = merge(baseConfig, {
target: 'electron-renderer',
entry: {
app: './src/client/app.tsx',
},
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
cacheDirectory: true,
babelrc: true,
},
},
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
},
{
test: /\.(gif|png|jpe?g)$/,
use: [
'file-loader',
{
loader: 'image-webpack-loader',
options: {
bypassOnDebug: true,
},
},
],
},
{
test: /\.svg$/,
use: ['svg-inline-loader?classPrefix'],
},
{
test: /\.md$/i,
use: ['raw-loader'],
},
// All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'.
{
enforce: 'pre',
test: /\.js$/,
use: ['source-map-loader'],
},
{
test: /\.worker\.ts$/i,
use: [
{
loader: 'comlink-loader',
options: {
singleton: true,
},
},
{
loader: 'babel-loader',
options: {
cacheDirectory: true,
babelrc: true,
},
},
],
},
],
},
plugins: [
new ForkTsCheckerWebpackPlugin({
typescript: {
diagnosticOptions: {
semantic: true,
syntactic: true,
},
},
}),
new HtmlWebpackPlugin({ template: path.resolve(__dirname, 'src/client/index.html') }),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development'),
'process.env.STORE': JSON.stringify(process.env.STORE || ''),
}),
new CopyPlugin({
patterns: [{ from: path.resolve(__dirname, 'static/'), to: path.resolve(__dirname, 'dist', 'static') }],
}),
],
});
This is the babel config:
module.exports = (api) => {
// This caches the Babel config by environment.
api.cache.using(() => process.env.NODE_ENV);
const developmentPlugins = ['@babel/plugin-transform-runtime', 'react-refresh/babel'];
const productionPlugins = [
// babel-preset-react-optimize
'@babel/plugin-transform-react-constant-elements',
'@babel/plugin-transform-react-inline-elements',
'babel-plugin-transform-react-remove-prop-types',
];
const development = api.env('development', 'test');
return {
presets: [
['@babel/preset-env', { targets: 'last 1 chrome version' }],
'@babel/preset-typescript',
'@babel/preset-react',
'@emotion/babel-preset-css-prop',
],
plugins: [
['@babel/plugin-proposal-decorators', { legacy: true }],
['@babel/plugin-proposal-class-properties', { loose: true }],
'@babel/plugin-proposal-optional-chaining',
'@babel/plugin-proposal-nullish-coalescing-operator',
...(development ? developmentPlugins : productionPlugins),
],
};
};
It works fine in webpack 4 (dev and prod) and only in dev mode in webpack 5. Any ideas how can we improve comlink support for webpack 5 in prod?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:9
- Comments:5
Top Results From Across the Web
To v5 from v4 - webpack
This guide aims to help you migrating to webpack 5 when using webpack directly. If you are using a higher level tool to...
Read more >facebook/create-react-app - Webpack 5 support overview
Overview of tasks needed for updating CRA to Webpack 5 - Some of the work will support both Webpack 4 + 5 but...
Read more >Webpack 5 Adoption - Next.js
Next.js has adopted webpack 5 as the default for compilation. We've spent a lot of effort into ensuring the transition from webpack 4...
Read more >So You Want CRA With Webpack 5 Support | Stuff Hasan Says
CRA did not release a new version with Webpack 5 support yet. However, you can still make it work using their wp5 branch...
Read more >Webpack 5 Migration - Nx
Webpack 5 comes with Nx 13, and your apps should work as long as you use compatible webpack plugins (or don't have customized...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m getting the same
__webpack_exports__ is not defined
error in prod. Webpack 5. No error in development mode.I got an error in only webpack 5 prod like that. Anyone has same issue ?
optimization.usedExport: false
it seem a workaround for me