next-on-pages: [🐛 Bug]: Not-found page doesn't work with last vercel version v31.2.0 in edge runtime
next-on-pages environment related information
System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 22.4.0: Mon Mar 6 21:00:41 PST 2023; root:xnu-8796.101.5~3/RELEASE_ARM64_T8103 CPU: (8) arm64 Apple M1 Memory: 16 GB Shell: /bin/zsh Binaries: Node: 18.15.0 Yarn: 1.22.17 npm: 9.5.0 pnpm: 8.6.5 Package Manager Used: yarn (classic) Relevant Packages: @cloudflare/next-on-pages: 1.4.0 vercel: N/A next: N/A
Description
Hi guys.
I tried to run npx @cloudflare/next-on-pages on Friday and got this error. (Everything was fine a day before).
Vercel version had been up to 31.2.0 this day so maybe that was the problem.
When I tried to add export const runtime = "edge"; to not-found.tsx page I’ve got this error:
not-found.tsx
export const runtime = "edge";
export default async function NotFoundPage() {
return (
<html lang="en">
<body>
<div>test</div>
</body>
</html>
);
}
Reproduction
No response
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?
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 66 (18 by maintainers)
Commits related to this issue
- edge prerendering on Cloudflare ⚡ - deleted `not-found.tsx` per cloudflare/next-on-pages#413 and cloudflare/next-on-pages#174 - added `export const runtime = 'edge';` to all `layout.tsx` files — committed to adamstambouli/app-playground by adamstambouli 5 months ago
- edge prerendering on Cloudflare ⚡ - deleted `not-found.tsx` per cloudflare/next-on-pages#413 and cloudflare/next-on-pages#174 - added `export const runtime = 'edge';` to all `layout.tsx` files — committed to adamstambouli/app-playground by adamstambouli 5 months ago
- edge prerendering on Cloudflare ⚡ - deleted `not-found.tsx` per cloudflare/next-on-pages#413 and cloudflare/next-on-pages#174 - added `export const runtime = 'edge';` to all `layout.tsx` files — committed to adamstambouli/app-playground by adamstambouli 5 months ago
- edge prerendering on Cloudflare ⚡ - deleted `not-found.tsx` per cloudflare/next-on-pages#413 and cloudflare/next-on-pages#174 - added `export const runtime = 'edge';` to all `layout.tsx` files — committed to adamstambouli/app-playground by adamstambouli 5 months ago
- edge prerendering on Cloudflare ⚡ - deleted `not-found.tsx` per cloudflare/next-on-pages#413 and cloudflare/next-on-pages#174 - added `export const runtime = 'edge';` to all `layout.tsx` files — committed to adamstambouli/app-playground by adamstambouli 5 months ago
- edge prerendering on Cloudflare ⚡ - deleted `not-found.tsx` per cloudflare/next-on-pages#413 and cloudflare/next-on-pages#174 - added `export const runtime = 'edge';` to all `layout.tsx` files — committed to adamstambouli/app-playground by adamstambouli 5 months ago
- edge prerendering on Cloudflare ⚡ - deleted `not-found.tsx` per cloudflare/next-on-pages#413 and cloudflare/next-on-pages#174 - added `export const runtime = 'edge';` to all `layout.tsx` files — committed to adamstambouli/app-playground by adamstambouli 5 months ago
- edge prerendering on Cloudflare ⚡ - deleted `not-found.tsx` per cloudflare/next-on-pages#413 and cloudflare/next-on-pages#174 - added `export const runtime = 'edge';` to all `layout.tsx` files — committed to adamstambouli/app-playground by adamstambouli 5 months ago
- edge prerendering on Cloudflare ⚡ - deleted `not-found.tsx` per cloudflare/next-on-pages#413 and cloudflare/next-on-pages#174 - added `export const runtime = 'edge';` to all `layout.tsx` files — committed to adamstambouli/app-playground by adamstambouli 5 months ago
I was able to get the app to build. I just added the
not-found.tsxfile to the app folder to resolve the/_not-foundbug.Then to overcome the
_errorissue, I couldn’t fix it with the app router custom errors but I just added custom errors to thepagesfolder.These files are just very simple for now:
Now the app builds with
npx @cloudflare/next-on-pages@1.*Update:
To get it to work with Internationalisation… it was more complex but I added a blank global layout for the
not-found.tsxroute to work:Then I have a folder structure like this:
I added
<html>and<body>tags to mynot-found.tsxfile then in my[lang]/layout.tsxfile I continue to handle all the localisation stuff like normal, and you can set up thelanganddirectionhtml attributes.@nikitaeverywhere I had the same issue, and I was able to solve it by using the latest beta release. Just change the build command to
Got it thanks, the complexity of this nextjs is ridiculous i will try to pull out the react components and put them into a vanilla react project.
same error, so annoying. remix just worked out of the box. I will side with joe armstrong the creator of erlang here RIP, when he said NPM and the node ecosystem is simply wack, taking something that should be smoothly and easily and adding a layer of 3 PhDs required just to deploy a project.
@dario-piotrowicz I still have this issue locally, I have only one not-found.js in top level
@emrecoban i found my problem. i used the
generateMetadatain the layout. seams like the layout also have to be static if using a not found.But this doesn’t show the warning for the dynamic not-found page
I see @nikitaeverywhere I’m glad that it’s not something we’re causing 😄 (but of course I’m sad that Next.js seem to present this many issues around CSP 🥲)
Anyways thanks a ton for sharing the Next.js issue, I gave it a quick scan through and it does feel like something something that could definitely come in handy to be aware of and keep in mind! so again thanks a bunch for sharing this info! ❤️
@xanderim @dario-piotrowicz thanks for the feedback. I changed the build command in CloudFlare page settings, and both “latest”
npx @cloudflare/next-on-pages@1andnpx @cloudflare/next-on-pages@0.0.0-2b5c8f2work as of now.nextjs 14 is however totally incapable of handling CSP but that’s unrelated 😄
Thanks.
Thank you so much, Dario! I’ll give it a shot sometime soon. I appreciate your work!
Hi all, this popped into my head just earlier, but you can probably do something like the following for your build command as a temporary workaround. The real fix would be Vercel resolving this.
Been having the same issue as you folks mentioned.
What ended up working for us. Which fixes the deploy, but still fails a runtime
src/app/error.tsxwith"use client"directivesrc/app/not-found.tsxwith"use client"directivesrc/pages/404.js(No directive)src/pages/404.js(No directive)src/app/layout.tsx.(PS: I’m using
src/appfolder):Aside from that, the usuals. 😃
If it helps. This is a permalink to the commit that worked in our project 😄 https://github.com/JSConfCL/turuleca/tree/c9b2060aab57f7d0c0bb5b56ff56f6ffa231c10a
Though as mentioned, now we are getting some client-side errors. ad924d6e.turuleca.pages.dev
Console
@microooji Sure. Example
app/layout.tsx:Without
app/not-found.tsx, this is the error I see when runningnpx @cloudflare/next-on-pages@1:@emrecoban awesome! no problem! thanks so much for confirming that’s all good now (or at least as good as it can be given our limitations 😅) ❤️
I’ve just merged #418 which introduces a temporary workaround for this issue, it allows the use of a not-found page as long as it doesn’t contain runtime logic
It is not ideal but the best we can do for now, I’ve marked this issue as
blocked by externalas we’ll have to investigate if maybe Vercel/Next can the generation of serverless functions for such routes on their end@dario-piotrowicz after adding middleware.ts to the bootstrapped default nextjs project (
npx create-next-app@latest) as per their docs (literally copy-paste), I’ve got the following error:And after adding missing pages and marking all as
export const runtime = "edge";,I still get this:
(latest available)
Does it mean no way to run it on Cloudflare?
PR https://github.com/cloudflare/next-on-pages/pull/585 has closed this issue, although the situation is still not perfect I would keep this issue closed so not to keep the conversation going, making it too diluted/unfocused
What things should work like right now in applications using the App router (in the latest
betarelease and from the next stable release):not-foundroutes need to be static and not have server side logic (as per https://github.com/cloudflare/next-on-pages/pull/418), if they do the build process is expected to failassuming that the app has a static
not-foundroute, the app can have a root layout that does have server side (edge) logic (as per https://github.com/cloudflare/next-on-pages/pull/585)If you see that any of the two points above doesn’t work as expected please comment here and we can reopen this issue, if you spot anything else please let’s open a new issue focused on that specific problem 🙏
Sorry for the trouble here, this one is a bit of a painful issue, hopefully the latest changes help the situation 😅
Hi all, I’ve opened #585 to fix this issue, the changes make it so that invalid
_errorfunctions generated when you have a layout that uses the edge runtime and also a static not-found route get ignored.You still however cannot have a not-found route using the edge runtime.
Please give the prerelease a try and let me know if it works for you 🙏
@anonymouscatcher this issue seems caused by how Vercel builds functions and it is a bit of our control to fix, one possible solution I thought of was allowing users to ask next-on-pages to ignore invalid routes as sometimes those are actually ok to ignore (like in the layout/not-found case mentioned in this thread and reproduced in this application).
I implemented that here: https://github.com/cloudflare/next-on-pages/pull/497, the PR hasn’t made much progress since I was trying to get the team’s feedback on this since it’s really not a super elegant solution.
if you could, could you just the prerelease a try and let me know what you think? I would surely appreciate external feedback on this.
If the solution above works reasonably well for people I think I can push for it with the team and merge it soon, so again I’d be very thankful if people could give it a go and let me know if it works for them 🙂
I get the error message about the missing edge runtime on the _not-found and _error route (both files do not exist in this project) when I try to work with
next/headersin the layout.tsx file. Once I remove this everything is fine.@vader1359 I’m pretty sure you’re experiencing something different, would it be possible for you to create a minimal reproduction of it to share and open a new issue for it?
FYI this worked for us. Thanks!
After trying several things the only solution that worked for me was to remove
export const runtime = "edge"from both mynot-found.tsxandapp/layout.tsx.the fix @tao mentioned worked for me, in the sense that it got
@cloudflare/next-on-pagesto build. BUT the only problem is that when the user goes to a not found route (ie/asdf), the/pages/404.jsis rendering instead of/app/not-found.tsx. I can work around this by just importing the same component used in/app/not-found.tsxbut this seems hacky especially since I’m trying to use only the app router.I guess this proves further that
@cloudflare/next-on-pageshas issues with error and not found pages in the app router when they use the edge runtime, but not for the pages router.@dario-piotrowicz appreciate anything you can do for this 💪
I did
npm i @cloudflare/next-on-pages@0.0.0-705a95bI dont get why this keeps happening in the cloudflare pipeline