呈现页面“ / 404”时发生错误:TypeError:res.writeHead不是函数-下一个Js

时间:2020-11-04 13:14:38

标签: javascript reactjs next.js i18next react-i18next

构建时出现404错误,我使用了下一个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}}',
})

1 个答案:

答案 0 :(得分:0)

我认为您正在运行next-i18next不支持的下一个导出。

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