Nextjs, next-on-pages, "hanging Promise was canceled"
Hi all, I'm trying to build a statically rendered site on Pages using Next.
I have a dynamic route as follows:
/app/(content)/articles/[slug]
that will render content pulled from a headless CMS.
When I use npm run dev
with Next, these routes work fine. but when I build the site with npx @cloudflare/next-on-pages@1
and then use wrangler to do a preview, it works for other non-dynamic pages but throws on the [slug] with:
A hanging Promise was canceled. This happens when the worker runtime is waiting for a Promise from JavaScript to resolve, but has detected that the Promise cannot possibly ever resolve because all code and events related to the Promise's I/O context have already finished.
✘ [ERROR] Uncaught (in response) Error: The script will never generate a response.
I've been trying to reduce to solve, and removed everything I can imagine so that I've literally got this as my page.js
for the [slug]
route:
Even that generates the hanging Promise error, which....I dont' get. I suspect I'm missing something with how generateStaticParams works with next-on-pages? Or...well, I don't know. That's why I'm here. 🙂
Any ideas on why this page is not working, even when there are no outside calls/async functions (so to speak)?13 Replies
If it matters: other pages that call my headless CMS work and show content. If I remove this route, I can build the site and preview it with no errors. It's only when I add this dynamic route that the promise-related errors start AND it's only on this dynamic [slug] route that I get the error. Other pages still render fine with next-on-pages and wrangler.
and if it helps, a repo with the rest of the code (including the original pages.js for the [slug] route) - https://github.com/mbakaitis/san-next-flare-site
GitHub
GitHub - mbakaitis/san-next-flare-site
Contribute to mbakaitis/san-next-flare-site development by creating an account on GitHub.
fwiw,
generateStaticParams
won't actually do anything if you use the edge runtime because it creates an edge function for the route instead of prerendering the static pages.
If you try doing next build
and next start
, does the error also occur? If it only occurs with next-on-pages+wrangler, please can open an issue on the next-on-pages repository for this so that it can be looked into (with a link to the repro) and not forgotten - i dont have time to try and setup sanity and look into it at the moment.next build and start work fine with both this simplified version and the original. I only get the promise errors with next-on-pages/wrangler
:/ yeah please open an issue on the repo then 🙂
on the next-on-pages repo?
Yes please
so if I remove the export for edge runtime? @Cloudflare/next-on-pages throws an error and refuses to build. are you saying I don't even need the generateStaticParams at all with next-on-pages?
If you opt out of the edge runtime, you'll need to export a route segment config option of
export const dynamicParams = false;
so it doesn't generate a lambda fallback function
If you use the edge runtime for a route, no static pages will be generated for it, so generateStaticParams will have no effectOK, so if I literally remove everything related to the CMS and hard code everything, no more promise errors. If I leave that stuff but remove the
export const runtime='edge'
, I get this:
that's after the vercel build completes
So I'm confused, I'm sorry to say. I'm trying to distill my repo down to a really simple branch that can repro the problem. Going all the way to hard-coding doesn't seem to do it. It all seems to be around this dynamic route, but I'm struggling to figure out how to show it repro without also having you get access to a Sanity dataset that it would use.Yes you need to export the route segment config option I said above to tell nextjs not to generate a fallback lambda function when using dynamic routes that don't use the edge runtime.
And that was it.
dynamicParams
and now it built and is working with the original with no errors. As always: HUGE thanks! I think that did it.Glad to hear it's working fine now 🙂