Next.js uses this folder structure for routing, so you can only have page components in it. You’ll need to move your components out of pages/ to fix the issue.
Solution 2 :
I can’t tell just by the code you posted here, but if you are trying to use “getStaticPaths” with “fallback: true”, you have to add a condition to check if isFallback, like this:
If you don’t want to render a fallback component you can use fallback: “blocking” and it will SSR your page if it is not available. Beware that if your user (or crawler) is accessing a page for the first time it can take a while until the page is completely rendered (and during this time the page will be blank with no interaction).
Problem :
I have this component that works totally fine on dev mode but when building it tells me that the open prop is undefined even though it works fine and when I console.log it on localhost I get the correct result.
info - Creating an optimized production build info - Compiled successfully
info - Collecting page data [= ] info - Generating static pages (0/51)
Error occurred prerendering page "/components/FAQ". Read more: err.sh/next.js/prerender-error
TypeError: Cannot read property 'open' of undefined
I can’t tell if this is a bug from NextJS side or what, I have been trying to rebuild the project for a while and this same error keeps popping. I have this same error on another component (basically the same concept where I’m passing props this same way). Any help would be really appreciated, thanks
Comments
Comment posted by juliomalves
Do you get the error when running
Comment posted by tylerdurden
I get it when running npm run build which is next build
Comment posted by err.sh/next.js/prerender-error
info – Creating an optimized production build info – Compiled successfully info – Collecting page data [= ] info – Generating static pages (0/51) Error occurred prerendering page “/components/FAQ”. Read more:
Comment posted by apinanyogaratnam
Thanks man, components definitely needs to be out of pages