Hello Netlify team and community,
I deployed a Next js app that has SSG pages and a single API route with the Netlify Nextjs plugin.
All pages are either static or SSG with no revalidate flag.
I expected only one function to be created for the API route since the rest of the routes should be static files served via the CDN. However, to my surprise, I could see functions created for each page in my app. Plus they are exposed via https://DOMAIN/.netlify/functions/FUNCTION as well.
Here’s an example - https://sarathkcm.netlify.app/.netlify/functions/next_blog_slug - These URLs don’t work because they access the filesystem.
There are no logs on these functions when I load the corresponding route on my website - though I can see the logs when I directly access the function.
I’m not sure if this is an issue or my understanding of how SSG works is wrong
Is this the expected behavior? If so, why are those extra functions created and what is their purpose? Should I be worried because code that was supposed to be executed only at build time is now exposed as endpoints in the deployed version?
I wasn’t sure if this post belongs to the support category as nothing is failing with the deployment or functionality of my app. I just wanted to have a better understanding of how the app gets deployed and served.
Hi @sarathkcm,
If you use Next js plugin version 4, then only 3 functions would be generated that should work for the entire site.
1 Like
Hi @hrishikesh,
Thank you, that was fast. I think I’ll upgrade to Next 12 and the plugin version 4.
I was wondering that since the routes are SSG, are these functions really used (because they don’t seem to work anyway)?
Regards
Sarath
Statically generated files should not use functions, yes. Are you using next export
?
No, I’m using ‘next build’, the pages have getStaticProps and getStaticPaths, and no getServerSideProps.
This made the website very slow compared to the setup I had with plugin version 3.9 (and Nextjs 10.2.3). At every page load, the __netlify-handler
function was being called and was erroring because it couldn’t find fs/promises. The pages were loading fine as they might have gotten generated during the build, but slower with each route transition causing a full reload. However, there were errors on the console citing 500 error codes returned from the functions. (/_next/data/xxxx/data.json
).
I don’t know if either NextJs/Netlify is supposed to work this way. I was under the impression that pages with SSG and no ISR won’t need functions on the server, as technically it is possible to serve them from the static folder as plain HTML/CSS/js even without next export
.
For now, I’m going back to NextJS plugin 3.9 which doesn’t seem to cause any issues with the website.
Thank you for the support.
Thanks & Regards
Sarath