[英]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.