Next.js Discord

Discord Forum

Webpack, babel loader - "Spread children are not supported in React"

Unanswered
Masai Lion posted this in #help-forum
Open in Discord
Masai LionOP
Hi, been attempting to build my next application to support older browsers - some of our code uses a spread for components. We're using the @babel/preset-react preset

In our next js config, we still error with Spread children are not supported in React. on build.

( It's erroring on a component with a usage like this: {...Components} )

I'm using webpack like the following in our nextjs config:

webpack(config) {
  config.module.rules.push({
    test: /\.(js|tsx|ts)$/i,
    exclude: /node_modules/,
    use: {
      loader: 'babel-loader',
      options: {
        presets: [
          '@babel/preset-env',
          'next/babel',
          '@babel/preset-typescript',
          '@babel/preset-react',
          '@babel/preset-flow',
        ],
        plugins: [
          ['@babel/plugin-transform-react-jsx'],
          ['@babel/plugin-proposal-optional-chaining'],
          ['@babel/plugin-transform-spread'],
        ],
      },
    },
  });


If anyone has any expertise on webpack with this - that would be amazing

2 Replies

Toyger
you probably can do it without changing webpack at all, just package.json browserlist https://nextjs.org/docs/architecture/supported-browsers#browserslist
Masai LionOP
Unfortunately we've seen it fall over despite specifying browsers in the package.json, specific things like
- logical-assignment-operators
- optional-chaining

are included in the build even with older browsers specified which don't support them