Reputation: 31779
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?
Upvotes: 28
Views: 33401
Reputation: 1
I encountered the same problem when deploying a output: "export"
app to Firebase hosting. The solution:
// next.config.js
const nextConfig = {
...
trailingSlash: true
}
Firebase assumes that a page for an url "/about" will be located in "/about/index.html", not: "/about.html" (which next.js defaults to)
Upvotes: 0
Reputation: 452
my case was because you have the "dev" script running in the same time
Upvotes: 13
Reputation: 5825
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
.
Upvotes: -1
Reputation: 1581
Sometimes the problem happens when we are building and we have another terminal running yarn dev
Upvotes: 40
Reputation: 5854
In my case, I was using getStaticProps
and getStaticPaths
. fallback
prop was set to false
. Changing it to true
fixed the issue.
Upvotes: 2
Reputation: 47
In my case, I solved a similar issue by deleting 'node_modules' by running rm -rf node_modules
and installed the packages again.
Upvotes: 0
Reputation: 585
In my case, running:
npm i --save --legacy-peer-deps
fixed the issue.
Upvotes: 0
Reputation: 374
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 :)
Upvotes: 5
Reputation: 10069
I just hit a similar error, and I had simply forgotten to run next build
before next export
!
Upvotes: 5
Reputation: 31779
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" }
}
};
}
};
Upvotes: 7