如何解决呈现页面“ / 404”时发生错误:TypeError:res.writeHead不是函数-下一个Js
终端:
[===]导出(0/3) 呈现页面“ / 404”时发生错误。了解更多:https://err.sh/next.js/prerender-error TypeError:res.writeHead不是redirectWithoutCache上的函数(/node_modules/next-i18next/dist/commonjs/utils/redirect-without-cache.js:12:7) ...
在呈现页面“ /404.html”时发生错误。了解更多:https://err.sh/next.js/prerender-error TypeError:res.writeHead不是函数 在redirectWithoutCache(/node_modules/next-i18next/dist/commonjs/utils/redirect-without-cache.js:12:7)
[=]导出(2/3) 呈现页面“ /”时发生错误。了解更多:https://err.sh/next.js/prerender-error TypeError:res.writeHead不是函数 在redirectWithoutCache(/node_modules/next-i18next/dist/commonjs/utils/redirect-without-cache.js:12:7) ...
导出(3/3) 错误:导出在以下路径上遇到的错误: / / 404 /404.html 在exportApp(/node_modules/next/dist/export/index.js:24:1103)
配置文件:
next.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
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}}',})
解决方法
我认为您正在运行next-i18next不支持的下一个导出。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。