Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[🐛 Bug]: Build fails if getStaticPaths return an empty array #743

Open
1 task
gabrielf opened this issue Apr 12, 2024 · 2 comments
Open
1 task

[🐛 Bug]: Build fails if getStaticPaths return an empty array #743

gabrielf opened this issue Apr 12, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@gabrielf
Copy link
Contributor

next-on-pages environment related information

System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 23.4.0: Fri Mar 15 00:12:49 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T6020
CPU: (12) arm64 Apple M2 Pro
Memory: 16 GB
Shell: /bin/zsh
Package Manager Used: npm (9.8.1)

Relevant Packages:
@cloudflare/next-on-pages: 1.11.0
vercel: N/A
next: 14.2.0

Description

getStaticPaths is used to control what pages to generate at build time for a dynamic route. Returning an empty array means "build no pages" for this route. This can happen when the content on the path varies over time and there may be no content at all or it can be used to hide test-pages in production for example.

Having getStaticPaths return nothing works with npm run build && npm start but fails the next-on-pages build with the following error:

⚡️ Completed `npx vercel build`.

⚡️ ERROR: Failed to produce a Cloudflare Pages build from the project.
⚡️ 
⚡️ 	The following routes were not configured to run with the Edge Runtime:
⚡️ 	  - /[maybe]
⚡️ 
⚡️ 	Please make sure that all your non-static routes export the following edge runtime route segment config:
⚡️ 	  export const runtime = 'edge';
⚡️ 
⚡️ 	You can read more about the Edge Runtime on the Next.js documentation:
⚡️ 	  https://nextjs.org/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes

Adding runtime edge to the route yields another error asking you to change edge to experimental-edge which in turn makes the build succceed but the route fail with a 500 error.

Reproduction

https://github.com/gabrielf/getstaticpaths-empty-return

Pages Deployment Method

None

Pages Deployment ID

No response

Additional Information

No response

Would you like to help?

  • Would you like to help fixing this bug?
@gabrielf gabrielf added the bug Something isn't working label Apr 12, 2024
@james-elicx
Copy link
Contributor

When the paths array is empty, the Vercel CLI generates a Node.js function for the route, and there isn't really a way for us to be able to tell if it's supposed to be safe to ignore... I'm not sure there's much we could do here.

Maybe we could add a CLI option like --ignore-invalid-routes=[maybe] - is that the kind of thing that you'd be after here?

@gabrielf
Copy link
Contributor Author

I wish I understand the build process better… Building with MAYBE=false npm run build and then running with npm start will give a 404 when navigating to http://localhost:3000/maybe so that is what I'd expect next-on-pages to behave also.

If the behavior of npm run build + npm start is not possible to realize using next-on-pages without introducing a cli option then you can close this issue. I would rather find a workaround in my app than introducing another cli option.

At least this issue exists so other may find it when googling so that makes me happy :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants