Nextjs export gives Cannot find module for page

Total
1
Shares

Hi I just started playing around with nextjs to see if it fits my use case. I wanted to export the site with some dynamic routes.

My pages folder structure is like below

page
  locales
    [locale]
      [slug].js

When I run next develop I can access the page at http://localhost:3000/locales/de-DE/summer-dress-f.

So now im trying to export the page with next.config.js like

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

next build runs fine but when I run next export I get the error

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)

Any ideas what am I missing here?


Solution

Finally figured it out. The pathmap should look like

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

Your email address will not be published. Required fields are marked *