title: Error occurred prerendering page "/404" : TypeError: res.writeHead is not a function - Next Js
body: <p>a 404 error is when build time, I using next js</p>
  <p>Terminal :</p>
  <p>[ ===] Exporting (0/3)
  Error occurred prerendering page &quot;/404&quot;. Read more: <a href="https://err.sh/next.js/prerender-error" rel="nofollow noreferrer">https://err.sh/next.js/prerender-error</a>
  TypeError: res.writeHead is not a function at redirectWithoutCache (/node_modules/next-i18next/dist/commonjs/utils/redirect-without-cache.js:12:7)
  ...</p>
  <p>Error occurred prerendering page &quot;/404.html&quot;. Read more: <a href="https://err.sh/next.js/prerender-error" rel="nofollow noreferrer">https://err.sh/next.js/prerender-error</a>
  TypeError: res.writeHead is not a function
  at redirectWithoutCache (/node_modules/next-i18next/dist/commonjs/utils/redirect-without-cache.js:12:7)</p>
  <p>[=   ] Exporting (2/3)
  Error occurred prerendering page &quot;/&quot;. Read more: <a href="https://err.sh/next.js/prerender-error" rel="nofollow noreferrer">https://err.sh/next.js/prerender-error</a>
  TypeError: res.writeHead is not a function
  at redirectWithoutCache (/node_modules/next-i18next/dist/commonjs/utils/redirect-without-cache.js:12:7)
  ...</p>
  <p>Exporting (3/3)
  Error: Export encountered errors on following paths:
  /
  /404
  /404.html
  at exportApp (/node_modules/next/dist/export/index.js:24:1103)</p>
  <p>config files :</p>
  <p>next.config.js</p>
  <pre><code>const { nextI18NextRewrites } = require('next-i18next/rewrites')
  
  const localeSubpaths = {
    fa: 'fa',
    en: 'en'
  }
  
  const withSass = require(&quot;@zeit/next-sass&quot;);
  const withLess = require(&quot;@zeit/next-less&quot;);
  const withCSS = require(&quot;@zeit/next-css&quot;);
  
  const isProd = process.env.NODE_ENV === &quot;production&quot;;
  
  // fix: prevents error when .less files are required by node
  if (typeof require !== &quot;undefined&quot;) {
    require.extensions[&quot;.less&quot;] = (file) =&gt; {};
  }
  
  module.exports = withCSS({
    rewrites: async () =&gt; nextI18NextRewrites(localeSubpaths),
    publicRuntimeConfig: {
      localeSubpaths,
    },
    cssModules: true,
    cssLoaderOptions: {
      importLoaders: 1,
      localIdentName: &quot;[local]___[hash:base64:5]&quot;,
      url: false
    },
    ...withLess(
      withSass({
        lessLoaderOptions: {
          javascriptEnabled: true,
        },
        webpack (config, options) {
          config.module.rules.push({
            test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2)$/,
            use: {
              loader: 'url-loader',
              options: {
                limit: 100000
              }
            }
          })
          return config
        }
      }),
    ),
    exportTrailingSlash: true,
    exportPathMap: function() {
      return {
        '/': { page: '/' }
      };
    },
  });
  
  </code></pre>
  <p>i18n.js</p>
  <pre><code>const NextI18Next = require('next-i18next').default
  const { localeSubpaths } = require('next/config').default().publicRuntimeConfig
  const path = require('path')
  
  module.exports = new NextI18Next({
    defaultLanguage: 'fa',
    otherLanguages: ['en'],
    defaultNS: 'common',
    localeSubpaths: {
      fa: 'fa',
      en: 'en',
    },
    localePath: path.resolve('./public/static/locales'),
    localeStructure: '{{lng}}/{{ns}}',
  })
  </code></pre>