简体   繁体   English

预渲染页面“/404”时出错:TypeError: res.writeHead is not a function - Next Js

[英]Error occurred prerendering page "/404" : TypeError: res.writeHead is not a function - Next Js

a 404 error is when build time, I using next js 404 错误是在构建时,我使用下一个 js

Terminal :终端 :

[ ===] Exporting (0/3) Error occurred prerendering page "/404". [ ===] 导出 (0/3) 预渲染页面“/404”时出错。 Read more: https://err.sh/next.js/prerender-error TypeError: res.writeHead is not a function at redirectWithoutCache (/node_modules/next-i18next/dist/commonjs/utils/redirect-without-cache.js:12:7) ...阅读更多: https ://err.sh/next.js/prerender-error TypeError:res.writeHead 不是 redirectWithoutCache 的函数 (/node_modules/next-i18next/dist/commonjs/utils/redirect-without-cache.js :12:7) ...

Error occurred prerendering page "/404.html".预呈现页面“/404.html”时发生错误。 Read more: https://err.sh/next.js/prerender-error TypeError: res.writeHead is not a function at redirectWithoutCache (/node_modules/next-i18next/dist/commonjs/utils/redirect-without-cache.js:12:7)阅读更多: https ://err.sh/next.js/prerender-error TypeError:res.writeHead 不是 redirectWithoutCache 的函数 (/node_modules/next-i18next/dist/commonjs/utils/redirect-without-cache.js :12:7)

[= ] Exporting (2/3) Error occurred prerendering page "/". [=] 导出 (2/3) 预呈现页面“/”时出错。 Read more: https://err.sh/next.js/prerender-error TypeError: res.writeHead is not a function at redirectWithoutCache (/node_modules/next-i18next/dist/commonjs/utils/redirect-without-cache.js:12:7) ...阅读更多: https ://err.sh/next.js/prerender-error TypeError: res.writeHead 不是 redirectWithoutCache 的函数 (/node_modules/next-i18next/dist/commonjs/utils/redirect-without-cache.js :12:7) ...

Exporting (3/3) Error: Export encountered errors on following paths: / /404 /404.html at exportApp (/node_modules/next/dist/export/index.js:24:1103)导出 (3/3) 错误:导出在以下路径上遇到错误://404 /404.html at exportApp (/node_modules/next/dist/export/index.js:24:1103)

config files :配置文件:

next.config.js下一个.config.js

const { nextI18NextRewrites } = require('next-i18next/rewrites')

const localeSubpaths = {
  fa: 'fa',
  en: 'en'
}

const withSass = require("@zeit/next-sass");
const withLess = require("@zeit/next-less");
const withCSS = require("@zeit/next-css");

const isProd = process.env.NODE_ENV === "production";

// fix: prevents error when .less files are required by node
if (typeof require !== "undefined") {
  require.extensions[".less"] = (file) => {};
}

module.exports = withCSS({
  rewrites: async () => nextI18NextRewrites(localeSubpaths),
  publicRuntimeConfig: {
    localeSubpaths,
  },
  cssModules: true,
  cssLoaderOptions: {
    importLoaders: 1,
    localIdentName: "[local]___[hash:base64:5]",
    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: '/' }
    };
  },
});

i18n.js i18n.js

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}}',
})

I am supposed that you are running next export which next-i18next does not support.我假设您正在运行 next-i18next 不支持的下一个导出。

https://github.com/isaachinman/next-i18next/issues/780 https://github.com/isaachinman/next-i18next/issues/780

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TypeError:res.writeHead不是函数第6章使用MEAN进行全栈javascript开发 - TypeError: res.writeHead is not a function chapter 6 Fullstack javascript development with MEAN 在 Next JS 中预呈现页面时发生错误 - Error occurred prerendering page in Next JS 预呈现页面“/”时发生错误。 部署错误 Vercel | Next.js - Error occurred prerendering page "/". Deployment Error Vercel | Next.js res.writehead是否实际写入我的html页面的开头? - Does res.writehead actually write to the head of my html page? 如何使用 res.writeHead(301, { "Location": "/path/within/site" }) 在 http node.js 的 res.writehead 中附加警报消息? - How to attach alert message in res.writehead in http node.js with res.writeHead(301, { "Location": "/path/within/site" })? Next.js '在预渲染页面“/”时发生错误:错误:缩小反应错误 #321;' 在生产构建期间 - Next.js 'Error occurred prerendering page "/": Error: Minified React error #321;' during production build 我处理HTML5时是否必须在node.js中包含res.writeHead? - Should I have to include res.writeHead in node.js when I deal with HTML5? res.writehead和res.write的hapi等效项是什么? - What is the hapi equivalent of res.writehead and res.write? 预渲染页面“/404”时出错,页面/_error 出错:无法导出带有`getServerSideProps` 的页面 - Error occurred prerendering page "/404" and Error for page /_error: pages with `getServerSideProps` can not be exported 发送到客户端后无法设置标头 NextJS 重定向 res.writeHead getInitialProps - Cannot set headers after they are sent to the client NextJS redirect res.writeHead getInitialProps
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM