title: next production Build failed because of webpack/babel transpile issue
body: <p>I am getting following error while creating production build after setup jest + enzyme using reference of <a href="https://levelup.gitconnected.com/configuring-jest-for-next-js-react-and-babel-from-scratch-bb3b7751329b" rel="nofollow noreferrer">https://levelup.gitconnected.com/configuring-jest-for-next-js-react-and-babel-from-scratch-bb3b7751329b</a>. 
  It's working fine in dev mode. Any solution. It seems to be a transpile issue.</p>
  
  <pre><code>vijdadhi$ yarn build
  yarn run v1.22.4
  $ next build
  Browserslist: caniuse-lite is outdated. Please run next command `yarn upgrade`
  &gt; Using external babel configuration
  &gt; Location: ".../repo/babel.config.js"
  Creating an optimized production build  
  
  Failed to compile.
  
  ./src/pages/404.js
  SyntaxError: .../src/pages/404.js: Unexpected token (4:4)
  ```
    2 | export default function Custom404() {
    3 |   return (
  &gt; 4 |     &lt;h1&gt;404 - Page Not Found&lt;/h1&gt;
      |     ^
    5 |   );
    6 | }
    7 | 
  ```
  &gt; Build error occurred
  Error: &gt; Build failed because of webpack errors
      at build (.../node_modules/next/dist/build/index.js:10:900)
  error Command failed with exit code 1.
  info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
  vijdadhi$ 
  </code></pre>
  
  <p>Error logs</p>
  
  <pre><code>0 info it worked if it ends with ok
  1 verbose cli [
  1 verbose cli   '/usr/local/Cellar/node/14.2.0/bin/node',
  1 verbose cli   '/usr/local/bin/npm',
  1 verbose cli   'run',
  1 verbose cli   'build'
  1 verbose cli ]
  2 info using npm@6.14.4
  3 info using node@v14.2.0
  4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
  5 info lifecycle nextjs-docker@1.0.0~prebuild: nextjs-docker@1.0.0
  6 info lifecycle nextjs-docker@1.0.0~build: nextjs-docker@1.0.0
  7 verbose lifecycle nextjs-docker@1.0.0~build: unsafe-perm in lifecycle true
  8 verbose lifecycle nextjs-docker@1.0.0~build: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/vijdadhi/Public/personal/projects/Lloyds/dev/repo/ep-mgf-ui-dashbaord/node_modules/.bin:/Applications/google-cloud-sdk/bin:~/Library/Android/sdk/platform-tools:/Users/vijdadhi/.rbenv/bin:/usr/local/opt/openssl/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/sbin
  9 verbose lifecycle nextjs-docker@1.0.0~build: CWD: /Users/vijdadhi/Public/personal/projects/Lloyds/dev/repo/ep-mgf-ui-dashbaord
  10 silly lifecycle nextjs-docker@1.0.0~build: Args: [ '-c', 'next build' ]
  11 silly lifecycle nextjs-docker@1.0.0~build: Returned: code: 1  signal: null
  12 info lifecycle nextjs-docker@1.0.0~build: Failed to exec build script
  13 verbose stack Error: nextjs-docker@1.0.0 build: `next build`
  13 verbose stack Exit status 1
  13 verbose stack     at EventEmitter.&lt;anonymous&gt; (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
  13 verbose stack     at EventEmitter.emit (events.js:315:20)
  13 verbose stack     at ChildProcess.&lt;anonymous&gt; (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
  13 verbose stack     at ChildProcess.emit (events.js:315:20)
  13 verbose stack     at maybeClose (internal/child_process.js:1051:16)
  13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:287:5)
  14 verbose pkgid nextjs-docker@1.0.0
  15 verbose cwd /Users/vijdadhi/Public/personal/projects/Lloyds/dev/repo/ep-mgf-ui-dashbaord
  16 verbose Darwin 18.7.0
  17 verbose argv "/usr/local/Cellar/node/14.2.0/bin/node" "/usr/local/bin/npm" "run" "build"
  18 verbose node v14.2.0
  19 verbose npm  v6.14.4
  20 error code ELIFECYCLE
  21 error errno 1
  22 error nextjs-docker@1.0.0 build: `next build`
  22 error Exit status 1
  23 error Failed at the nextjs-docker@1.0.0 build script.
  23 error This is probably not a problem with npm. There is likely additional logging output above.
  24 verbose exit [ 1, true ]
  </code></pre>
  
  <p>1 .bablerc file is</p>
  
  <pre><code>{
    "presets": [
      "next/babel",
    ],
    "plugins": [
      [
        "styled-components",
        {
          "ssr": true,
          "displayName": true,
          "preprocess": false
        }
      ]
    ],
  }
  </code></pre>
  
  <ol start="2">
  <li>babel.config.js file is </li>
  </ol>
  
  <pre><code>module.exports = {
    "env": {
      "test": {
        "presets": [
          "@babel/preset-env",
          "@babel/react",
          "next/babel"
        ]
      },
      "development": {
        "presets": [
          "next/babel"
        ]
      }
    }
  }
  </code></pre>
  
  <ol start="3">
  <li>next.config.js file is</li>
  </ol>
  
  <pre><code>const withPlugins = require("next-compose-plugins");
  
  module.exports = withPlugins(
    [],
    {
  
      webpack: (config, {dev, isServer}) =&gt; {
         if (isServer) {
            return config;
         }
         var isProduction = config.mode === 'production';
         if(!isProduction) {
          config.optimization.minimize = false;
          config.optimization.minimizer = [];
         }
         return config
      }
   }
  );
  </code></pre>