24

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?

1
  • it works fine for me with the latest version with your provided config, I think it's something else going on for your app. Which version of next.js are you using?
    – eenagy
    Commented Jul 13, 2019 at 3:54

10 Answers 10

27

Sometimes the problem happens when we are building and we have another terminal running yarn dev

2
  • This is an interesting insight. I was trying to hit my own API via localhost which is required by some processes while building the site via getStaticProps. After switching to calling our production API (assume I stopped calling localhost:3000/API and started calling mysite.com/API) the build process was successful. Commented Aug 1, 2023 at 22:01
  • 1
    Thank you, this solved my issue. I had yarn dev running on the same project in another tab.
    – Altin
    Commented Sep 29, 2023 at 11:59
15

Running npm install seems to fix this.

1
  • 4
    Worked for me as well. Does anyone know as to what causes this? Commented Jan 9, 2023 at 17:56
10

my case was because you have the "dev" script running in the same time

7

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" }
      }
    };
  }
};
5

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

5

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 :)

2

In my case, I was using getStaticProps and getStaticPaths. fallback prop was set to false. Changing it to true fixed the issue.

0

In my case, running:

npm i --save --legacy-peer-deps

fixed the issue.

0

In my case, I solved a similar issue by deleting 'node_modules' by running rm -rf node_modules and installed the packages again.

-1

Incase it helps anyone else, I got the same error message when I incorrectly had capitals in the file name. E.g. WIP-sidebar.js.

Not the answer you're looking for? Browse other questions tagged or ask your own question.