question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Migration webpack 4 -> 5 and code splitting trouble antd

See original GitHub issue

What example does this report relate to?

with-styled-components

What version of Next.js are you using?

“next”: “10.2.3”

What version of Node.js are you using?

v14.16.1

What browser are you using?

Chrome

What operating system are you using?

macOS

How are you deploying your application?

Other platform

Describe the Bug

problem with the code splitting

Expected Behavior

assembly as in 4 webpack

To Reproduce

Hi !

We go from 4 to 5 webpacks, everything seems to work out, but there is a problem with the code splitting, namely with the packages of antd screens I attach the file next.config.js

Webpack 4: Снимок экрана 2021-09-02 в 17 05 41

Webpack 5: Снимок экрана 2021-09-02 в 17 15 59

Can you please tell me how to make the formation of packages as it was before, so that the webpack does not drag everything into one file _app.js ?

My config:

const webpack = require('webpack');

const withBundleAnalyzer = require('@next/bundle-analyzer')({
  enabled: process.env.ANALYZE === 'true',
});
const FilterWarningsPlugin = require('webpack-filter-warnings-plugin');
const { withSentryConfig } = require('@sentry/nextjs');
const withAntdLess = require('next-plugin-antd-less');

let CONFIG;

try {
  CONFIG = require('./etc/config');
} catch (e) {
  console.error(
    'Create config from one of examples. See /etc/ dir and copy one of .dev, .test or .prod config file for config.js!',
  );
  throw new Error(e);
}

const SentryWebpackPluginOptions = {
  dryRun: true,
};

const themeVariables = require('./src/.......').antDLessVars;

const config = withSentryConfig(
  withBundleAnalyzer(
    withAntdLess({
      typescript: {
        ignoreBuildErrors: true,
      },
  
      productionBrowserSourceMaps: false,
      trailingSlash: true,
      serverRuntimeConfig: CONFIG.SSR,
      publicRuntimeConfig: CONFIG.CLIENT,

      modifyVars: themeVariables,
      webpack: (config, { isServer, buildId }) => {
        config.plugins.push(
          new webpack.DefinePlugin({
            'process.env.SENTRY_RELEASE': JSON.stringify(buildId),
            'process.env.IS_CLIENT': JSON.stringify(!isServer),
            'process.env.IS_SERVER': JSON.stringify(isServer),
            'process.env.IS_DEV': JSON.stringify(process.env.NODE_ENV),
            'process.env.IS_DOCKER': JSON.stringify(process.env.IS_DOCKER),
          }),
          // new AntdDayjsWebpackPlugin(),
          new FilterWarningsPlugin({
            exclude: /mini-css-extract-plugin[^]*Conflicting order between:/,
          }),
        );

        if (isServer) {
          const antStyles = /antd\/.*?\/style.*?/;

          config.module.rules.unshift({
            test: antStyles,
            use: 'null-loader',
          });
        } else {
          config.plugins.push(new webpack.IgnorePlugin(/^(elastic-apm-node)$/));
        }

        config.resolve.alias['@ant-design/icons/lib/dist$'] = path.join(__dirname, 'icons.js');

        config.module.rules.unshift({
          test: /\.svg$/,
          use: ['@svgr/webpack', 'url-loader'],
        });

        return config;
      },
    }),
  ),
    SentryWebpackPluginOptions,
  );
  module.exports = config;

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
devdpontescommented, Nov 29, 2021

We also have an issue with webpack 5. It’s repeating packages. One example is Axios. All we did was to update nextjs version from 10 to 11. Also happens on v12.

Screenshot 2021-11-29 at 11 10 06 Screenshot 2021-11-29 at 11 09 40

EDIT: We’ve realised that with webpack 5, it actually puts commons into _app along with other chunks. We’re seeing a significant increase on page load downloaded JS, but we suspect it’s related to dynamic imports (next/dynamic).

2reactions
ggamvetas87commented, Feb 12, 2022

We also face the same issue after upgrading our project to next v12 and using webpack 5i It seems as the code splitting does not actually work, since the app.js file contains a lot code of other splitting chunks. Before the issue the app.js filesize was about 4-5KBs and now it has more than 600KB.

nextv12-webpack5-code-splitting-issue1

We have also tried to comment out all the next dynamic imports from app.js, but it seems as the issue persists, since on build process the app.js still contains code related to other components used via Context (that shouldn’t happen, since we are using code splitting).

We have also seen an increase on page load, and specifically at DomContentLoad, but we strongly believe that this is related to the code splitting failure and the significant increased filesize of the app.js, which actually forces the load of all other chunks that contain the same code.

PS: Is it possible to change the next.config.js configuration in order to apply a “custom” code spilitting until the issue has been resolved?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Migration webpack 4 -> 5 and code splitting trouble antd
Hi ! We go from 4 to 5 webpacks, everything seems to work out, but there is a problem with the code splitting,...
Read more >
To v5 from v4
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 >
reactjs - ant design - huge imports
Try using code splitting using webpack and react router. It will help you to load the modules asynchronously. This is ...
Read more >
Migration guide to Webpack 5 | Javascript by Flo - GinkoNote
Here is a guide to migrate a Webpack configuration based on Webpack 4 to Webpack 5. For a complete configuration of Webpack 4...
Read more >
5 Methods to Reduce JavaScript Bundle Size
There are multiple ways to implement code splitting using Webpack. Out of these, Dynamic Imports is one of the most used methods.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found