Nextjs 导出无法找到页面模块

Nextjs export gives Cannot find module for page

您好,我刚开始使用 nextjs 看看它是否适合我的用例。我想用一些动态路由导出站点。

我的页面文件夹结构如下

page
  locales
    [locale]
      [slug].js

当我 运行 next develop 我可以访问 http://localhost:3000/locales/de-DE/summer-dress-f 的页面。

所以现在我正在尝试使用 next.config.js 导出页面

module.exports = {
  exportPathMap: function() {
    return {
      "/locales/de-DE/summer-dress-f": {
        page: "/locales",
        query: { locale: "de-DE", slug: "summer-dress-f" }
      }
    };
  }
};

next build 运行 很好,但是当我 运行 next export 我得到错误

Error: Cannot find module for page: /locales
    at pageNotFoundError (/Users/bmathew/Desktop/workspace/next-demo/node_modules/next-server/dist/server/require.js:13:17)

知道我在这里遗漏了什么吗?

终于想通了。路径图应该看起来像

module.exports = {
  exportPathMap: function() {
    return {
      "/locales/de-DE/summer-dress-f": {
        page: "/locales/[locale]/[slug]",
        query: { locale: "de-DE", slug: "summer-dress-f" }
      }
    };
  }
};

运行 npm install 似乎解决了这个问题。

我刚刚遇到了类似的错误,我只是忘了在 next export!

之前 运行 next build

页面组件命名应该是唯一的。 所以我有 about.tsx 的名称:AboutPage 和 faqs.tsx 的名称:AboutPage 以及修改 faqs.tsx 使其唯一固定 :)