I am currently working on a 2-year-old NextJS application with the aim of implementing Contentful previews through the use of NextJS API Routes. The functions have been developed and they work fine locally. I am, however, having a tough time deploying them to Netlify.
The build overview shows “Deployed Functions and Edge Functions” ( screenshot 1), however, the Build Summary shows “No Edge Functions Deployed” ( screenshot 2). The build logs also contain the function bundling process. ( screenshot 3 ).
The custom functions directory has been specified in the netlify.toml file as shown below;
Following these declarations, I think Netlify now expects the serverless functions to run as Netlify Functions ( using the Netlify function’s syntax et al).
What I want is to have the Next.js API Routes deployed and accessible. Without the declaration, I am getting a 404 error when I try to access the function endpoint.
Which ones? The ones created by you or one created by Next.js Runtime? If it’s the latter, it worked because the Runtime declared it for you during the build. If it’s the former, it sounds unlikely that it would work without declaration.
What was amiss for anyone experiencing this issue was the netlify/next-runtime.
Unlike Netlify claims, this runtime is not automatically used within the build pipeline for much older projects (mine was a 3-year-old application). However, it is automatically used for new Next.js projects bootstrapped through the Netlify console. ( From my various testings )
You need to follow the manual installation process to install the runtime in order to have the Next.js API routes deployed.
thank you for coming back and letting us know what you used to resolve this problem and providing documentation. This will help others on this in the future.