Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nextjs export gives Cannot find module for page

Tags:

next.js

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?

like image 565
blessanm86 Avatar asked Jul 12 '19 09:07

blessanm86


Video Answer


4 Answers

Running npm install seems to fix this.

like image 75
Thingamajig Avatar answered Nov 11 '22 02:11

Thingamajig


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" }
      }
    };
  }
};
like image 37
blessanm86 Avatar answered Nov 11 '22 01:11

blessanm86


Page component naming should be unique. So I had about.tsx with name: AboutPage and faqs.tsx with name: AboutPage as well, amending faqs.tsx to be unique fixed it :)

like image 43
idiglove Avatar answered Nov 11 '22 03:11

idiglove


I just hit a similar error, and I had simply forgotten to run next build before next export!

like image 35
tremby Avatar answered Nov 11 '22 02:11

tremby