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]: Not-found page doesn't work with last vercel version v31.2.0 in edge runtime #413

Closed
1 task
AlexandrNetsvetov opened this issue Jul 30, 2023 · 70 comments · Fixed by #585
Closed
1 task
Assignees
Labels
app router This issue is related to the App router blocked by external This can't be currently solved because of external factors (Vercel/Next, Pages, etc...) bug Something isn't working

Comments

@AlexandrNetsvetov
Copy link

AlexandrNetsvetov commented Jul 30, 2023

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).

Screenshot 2023-07-30 at 19 50 32

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:

Screenshot 2023-07-30 at 19 57 47

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?
@AlexandrNetsvetov AlexandrNetsvetov added the bug Something isn't working label Jul 30, 2023
@BlackBerry009
Copy link

Yes. I have the same problem.

@dario-piotrowicz
Copy link
Member

Hi @AlexandrNetsvetov thank you very much for the issue 🙂

The second part of the issue is a duplicate of #288

The first could be a very similar issue, it's interesting that it worked on an older Vercel CLI but not on a new one, I'll investigate it

if you could share your code that'd be very helpful 🙏 , if that's not possible, anyways I'd just like to double-check, am I correct in thinking that you're using app directory? (as in pages you'd have 404.tsx/jsx instead I think?)


PS: @BlackBerry009, you as well, if you can share your code that could be very helpful 🙂 🙏 (if you experienced the first part of the issue this is the right place, if you experienced the second part please share info in #288)

@AlexandrNetsvetov
Copy link
Author

@dario-piotrowicz Thanks for your answer.

Yes, I'm using app directory.

I can't share my code but I'm ready to provide you all details that you need.

PS: I've added export const runtime = "edge"; field only because my build had been fallen with first error message. My not-found page used to worked without edge runtime for vercel 31.1.1.

@dario-piotrowicz
Copy link
Member

Thanks a lot for the info @AlexandrNetsvetov 😄

I'll investigate and if more info is needed I'll let you know 🙂 🙏

@dario-piotrowicz
Copy link
Member

@emrecoban
Copy link

emrecoban commented Aug 8, 2023

My app throws the same error.

Next v13.4.13
cloudflare/next-on-pages v1.5.0

@dario-piotrowicz dario-piotrowicz added the blocked by external This can't be currently solved because of external factors (Vercel/Next, Pages, etc...) label Aug 9, 2023
@dario-piotrowicz
Copy link
Member

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 external as we'll have to investigate if maybe Vercel/Next can the generation of serverless functions for such routes on their end

@emrecoban
Copy link

I've tried that solution, but the issue still occurs @dario-piotrowicz.

{
  "devDependencies": {
    "@cloudflare/next-on-pages": "https://prerelease-registry.devprod.cloudflare.dev/next-on-pages/runs/5786546906/npm-package-next-on-pages-418",
  }
}

Build logs in no edge runtime:

22:21:28.531 | ⚡️The following routes were not configured to run with the Edge Runtime:
22:21:28.531 | ⚡️ - /_not-found
22:21:28.531 | ⚡️
22:21:28.532 | ⚡️Please make sure that all your non-static routes export the following edge runtime route segment config:
22:21:28.532 | ⚡️ export const runtime = 'edge';

Build logs in edge runtime:

22:24:11.400 | ⚡️The following routes were not configured to run with the Edge Runtime:
22:24:11.401 | ⚡️  - /_error
22:24:11.401 | ⚡️
22:24:11.401 | ⚡️Please make sure that all your non-static routes export the following edge runtime route segment config:
22:24:11.401 | ⚡️ export const runtime = 'edge';

@dario-piotrowicz
Copy link
Member

@emrecoban are you sure the prerelease got installed correctly? 😓

can you double check and make sure that next-on-pages tells you that it's using the prerelease version?
(like this)

I just used the prerelease to deploy this application which is getting built correctly and working as expected:
https://ed46310b.next-apps-for-testing.pages.dev/

(If you confirm that you're indeed using the prerelease, can you spot something different between your application and mine that could make yours not work?)

@emrecoban
Copy link

emrecoban commented Aug 9, 2023

Finally I'm here. Okay, I updated next-on-pages, and then it worked. But I had to add Vercel@30.0.0 package, or something (I'm not sure). Because I couldn't update the package for a while as follow (The message I gave up to send).
_

It seems that the reason I got the error is cloudflare/next-on-pages not updated.

I'm investigating how to update the package to pre-version, but pnpm throws that error: No matching version found for @cloudflare/next-on-pages@0.0.0-d1839d6. I didn't get why pnpm throws this one.

I've checked the versions of cloudflare/next-on-pages, and have not found the commit d1839d6.

_

Okay, another issue is related to my app, anyway. Thanks a lot! @dario-piotrowicz

@dario-piotrowicz
Copy link
Member

@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 😅) ❤️

@vans163
Copy link

vans163 commented Aug 10, 2023

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.

@vans163
Copy link

vans163 commented Aug 10, 2023

20:37:52.323 | ➤ YN0000: │ /tmp/xfs-76265625 STDOUT Some issues need review, and may require choosing
-- | --
20:37:52.323 | ➤ YN0000: │ /tmp/xfs-76265625 STDOUT a different dependency.
20:37:52.323 | ➤ YN0000: │ /tmp/xfs-76265625 STDOUT
20:37:52.324 | ➤ YN0000: │ /tmp/xfs-76265625 STDOUT Run `npm audit` for details.
20:37:52.869 | ➤ YN0058: │ next-on-pages@https://github.com/cloudflare/next-on-pages.git#commit=5bfbbe15ce14369016992a7cca9f93847851be67: Packing the package failed (exit code 1, logs can be found here: /tmp/xfs-bf62a741/pack.log)
20:37:52.870 | ➤ YN0000: └ Completed in 1m 46s
20:37:52.870 | ➤ YN0000: Failed with errors in 1m 46s
20:37:53.996 | Error: Exit with error code: 1
20:37:53.997 | at ChildProcess.<anonymous> (/snapshot/dist/run-build.js)
20:37:53.997 | at Object.onceWrapper (node:events:652:26)
20:37:53.997 | at ChildProcess.emit (node:events:537:28)
20:37:53.998 | at ChildProcess._handle.onexit (node:internal/child_process:291:12)
20:37:54.007 | Failed: build command exited with code: 1
20:37:55.100 | Failed: error occurred while running build command

added like so

    "next-on-pages": "git+https://github.com/cloudflare/next-on-pages.git#5bfbbe15ce14369016992a7cca9f93847851be67",

@vans163
Copy link

vans163 commented Aug 10, 2023

Does anyone know how to force next-on-pages to be commit or branch bound?



20:58:32.965 | Executing user command: npx @cloudflare/next-on-pages@1
-- | --
20:58:35.048 | npm WARN exec The following package was not found and will be installed: @cloudflare/next-on-pages@1.5.0

even with this line in package.json it still pulls wrong version

 "next-on-pages": "git+https://github.com/cloudflare/next-on-pages.git#5bfbbe15ce14369016992a7cca9f93847851be67",

@dario-piotrowicz
Copy link
Member

@vans163 is there a reason why you can't use the PR's prerelase?

Also since the change made it into main it's also been published in the latest beta

@vans163
Copy link

vans163 commented Aug 10, 2023

@vans163 is there a reason why you can't use the PR's prerelase?

Also since the change made it into main it's also been published in the latest beta

I did npm i @cloudflare/next-on-pages@0.0.0-705a95b

  "dependencies": {
    "@cloudflare/next-on-pages": "^0.0.0-705a95b",

I dont get why this keeps happening in the cloudflare pipeline

09:54:20.388 | Executing user command: npx @cloudflare/next-on-pages@1
-- | --
09:54:22.876 | npm WARN exec The following package was not found and will be installed: @cloudflare/next-on-pages@1.5.0


@emrecoban
Copy link

emrecoban commented Aug 10, 2023

@vans163 I've checked my app's build logs, and then seen the same warn. You can ignore it.

Just check the devDependencies list:

01:35:41.009 | devDependencies:
01:35:41.009 | + @cloudflare/next-on-pages 0.0.0-54d6325
01:35:41.010 | + @tailwindcss/forms 0.5.4
01:35:41.010 | + vercel 30.0.0
01:35:41.010 |  
01:35:41.010 | Done in 29.2s
01:35:41.050 | Executing user command: npx @cloudflare/next-on-pages@1
01:35:47.290 | npm WARN exec The following package was not found and will be installed: @cloudflare/next-on-pages@1.5.0

Everything is okay in the app now.

You can install the 54d6325 in your project with:

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/next-on-pages/runs/5786546906/npm-package-next-on-pages-418

@vans163
Copy link

vans163 commented Aug 10, 2023

@vans163 I've checked my app's build logs, and then seen the same warn. You can ignore it.

Just check the devDependencies list:

01:35:41.009 | devDependencies:
01:35:41.009 | + @cloudflare/next-on-pages 0.0.0-54d6325
01:35:41.010 | + @tailwindcss/forms 0.5.4
01:35:41.010 | + vercel 30.0.0
01:35:41.010 |  
01:35:41.010 | Done in 29.2s
01:35:41.050 | Executing user command: npx @cloudflare/next-on-pages@1
01:35:47.290 | npm WARN exec The following package was not found and will be installed: @cloudflare/next-on-pages@1.5.0

Everything is okay in the app now.

You can install the 54d6325 in your project with:

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/next-on-pages/runs/5786546906/npm-package-next-on-pages-418

Yea same error



10:11:38.298 | ⚡️ Completed `npx vercel build`.
-- | --
10:11:40.688 |  
10:11:40.689 | ⚡️ ERROR: Failed to produce a Cloudflare Pages build from the project.
10:11:40.689 | ⚡️
10:11:40.689 | ⚡️ 	The following routes were not configured to run with the Edge Runtime:
10:11:40.689 | ⚡️ 	  - /_error
10:11:40.689 | ⚡️
10:11:40.690 | ⚡️ 	Please make sure that all your non-static routes export the following edge runtime route segment config:
10:11:40.690 | ⚡️ 	  export const runtime = 'edge';
10:11:40.690 | ⚡️
10:11:40.690 | ⚡️ 	You can read more about the Edge Runtime on the Next.js documentation:
10:11:40.690 | ⚡️ 	  https://nextjs.org/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes
10:11:40.690 |  
10:11:40.732 | Failed: Error while executing user command. Exited with error code: 1
10:11:40.743 | Failed: build command exited with code: 1
10:11:44.924 | Failed: error occurred while running build command

This is the repo, maybe if you have a chance to look I would really appreciate it. I have no idea whats wrong. It is using the app/ instead of pages/ feature of NEXTJS. Its a charity project to help out a not-for-profit.

https://github.com/vans163/link

@emrecoban
Copy link

@vans163 I've tried several ways, but couldn't be successful. I am not sure what causes this error. Although I added different versions of next-on-pages (included beta), it threw the same error. I should say that your packages are not working together. Maybe it is related to that.

 WARN  Issues with peer dependencies found
.
└─┬ pliny 0.1.1
  └─┬ kbar 0.1.0-beta.41
    └─┬ react-virtual 2.10.4
      └── ✕ unmet peer react@"^16.6.3 || ^17.0.0": found 18.2.0

@vans163
Copy link

vans163 commented Aug 10, 2023

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.

@vans163
Copy link

vans163 commented Aug 10, 2023

@vans163 I've tried several ways, but couldn't be successful. I am not sure what causes this error. Although I added different versions of next-on-pages (included beta), it threw the same error. I should say that your packages are not working together. Maybe it is related to that.

 WARN  Issues with peer dependencies found
.
└─┬ pliny 0.1.1
  └─┬ kbar 0.1.0-beta.41
    └─┬ react-virtual 2.10.4
      └── ✕ unmet peer react@"^16.6.3 || ^17.0.0": found 18.2.0

So moving the project out was gonna be a pain, I read carefully your PR #418 and hit a eureka. Deleting not-found from the app/ root made it automagically-gandalf-wizardry stop producing the _error artifact after compile. It compiled!

@vans163
Copy link

vans163 commented Aug 10, 2023

Now its giving

      "message": [
        "EvalError: Code generation from strings disallowed for this context"
      ],

visiting any page on the router lol..

EDIT: This is most likely due to the mdx templating engine to turn markdown into html code. Dead end it seems.

@dario-piotrowicz dario-piotrowicz added the app router This issue is related to the App router label Aug 22, 2023
@wuifdesign
Copy link

wuifdesign commented Aug 25, 2023

using the app router and adding a not-found.tsx still gives me the same error. I'm using @cloudflare/next-on-pages CLI v.1.5.1 but also tried the newest beta without a difference.

Is there any specific setting i have to set to get this working, as above is mentioned someone got a successful build.

⚡️ ERROR: Failed to produce a Cloudflare Pages build from the project.
⚡️ 
⚡️      The following routes were not configured to run with the Edge Runtime:
⚡️        - /_error
⚡️ 
⚡️      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

@always-maap
Copy link

removing app/not-found.tsx fixed it temporarily

https://github.com/always-maap/NIT-Academy

@dario-piotrowicz
Copy link
Member

Hi all, I've opened #585 to fix this issue, the changes make it so that invalid _error functions 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 🙏

@w33ts
Copy link

w33ts commented Dec 11, 2023

Thank you so much, Dario! I'll give it a shot sometime soon. I appreciate your work!

@dario-piotrowicz
Copy link
Member

dario-piotrowicz commented Dec 13, 2023

PR #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 beta release and from the next stable release):

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 😅

@nikitaeverywhere
Copy link

@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:

image

And after adding missing pages and marking all as export const runtime = "edge";,

image

I still get this:

image image

(latest available)

Does it mean no way to run it on Cloudflare?

@xanderim
Copy link

@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

npx @cloudflare/next-on-pages@0.0.0-2b5c8f2

@dario-piotrowicz
Copy link
Member

@xanderim thanks for confirming that the latest beta release does work 🙂

I've just cut a standard release so using the latest stable release should work fine now 🤞

@nikitaeverywhere please give it a try and let me know if it works for you 🙂

@nikitaeverywhere
Copy link

@xanderim @dario-piotrowicz thanks for the feedback. I changed the build command in CloudFlare page settings, and both "latest" npx @cloudflare/next-on-pages@1 and npx @cloudflare/next-on-pages@0.0.0-2b5c8f2 work as of now.

nextjs 14 is however totally incapable of handling CSP but that's unrelated :D

Thanks.

@dario-piotrowicz
Copy link
Member

@nikitaeverywhere I'm glad things work for you now 😄 🚀

Regarding Next.js 14 and CSP, sorry I am not aware of the incompatibility you're mentioning, is that something totally on Next.js? or is it something caused by our adapter? (if it's the latter please open a new gh issue for that, so that we can look into it 🙏)

@nikitaeverywhere
Copy link

Regarding Next.js 14 and CSP

@dario-piotrowicz it's on the NextJS side completely. I personally think NextJS is just not designed to support CSP. You can find a lot of lengthy threads with other people suffering.

So, as for Cloudflare, no worries at all :D

@dario-piotrowicz
Copy link
Member

dario-piotrowicz commented Jan 1, 2024

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! ❤️

adamstambouli added a commit to adamstambouli/app-playground that referenced this issue Jan 23, 2024
- 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
adamstambouli added a commit to adamstambouli/app-playground that referenced this issue Jan 23, 2024
- 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
adamstambouli added a commit to adamstambouli/app-playground that referenced this issue Jan 23, 2024
- 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
adamstambouli added a commit to adamstambouli/app-playground that referenced this issue Jan 23, 2024
- 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
adamstambouli added a commit to adamstambouli/app-playground that referenced this issue Jan 23, 2024
- 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
adamstambouli added a commit to adamstambouli/app-playground that referenced this issue Jan 23, 2024
- 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
adamstambouli added a commit to adamstambouli/app-playground that referenced this issue Jan 23, 2024
- 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
adamstambouli added a commit to adamstambouli/app-playground that referenced this issue Jan 23, 2024
- 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
adamstambouli added a commit to adamstambouli/app-playground that referenced this issue Jan 23, 2024
- 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
@anonymouscatcher
Copy link

@dario-piotrowicz I still have this issue locally, I have only one not-found.js in top level

npx @cloudflare/next-on-pages@latest
⚡️ ERROR: Failed to produce a Cloudflare Pages build from the project.
⚡️
⚡️ 	The following routes were not configured to run with the Edge Runtime:
⚡️ 	  - /_error
⚡️
⚡️ 	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

@switz
Copy link

switz commented May 24, 2024

I still have this issue locally, I have only one not-found.js in top level

seeing this same issue myself, has anyone found a solution? (generally wouldn't bump but its 2.5 months old)

@cameron-eth
Copy link

Hey all, I've built on top of morphic but everytime the search results post, the app re routes to the home page ?

@AlecKriebel
Copy link

For others experiencing this issue, upgrading from "vercel": "^31.1.0" to "vercel": "^32.4.1" (latest) in the Next.js project I was trying to build for pages fixed this for me.

@DeJayDev
Copy link

DeJayDev commented Jun 27, 2024

Upgrading the vercel dependency did not fix the error in my project, however I've seen successful builds by entirely removing the _error directory before running Next on Pages.

mkdir .vercel; echo '{"projectId":"_","orgId":"_","settings":{"framework":"nextjs"}}' > .vercel/project.json; npx vercel build; rm -rf .vercel/output/functions/_not-found*; rm -rf .vercel/output/functions/_error*; npx @cloudflare/next-on-pages --skip-build;

This command was written by @james-elicx in the Cloudflare Developers Discord, you can find the original conversation on this Answer Overflow Page

To use this command for production builds, I added it to my package.json as cf:build and changed the command to npm run cf:build. You will need to escape (\") all of the double quotes with this method. However, you can also get away with just pasting that as your build command in the Cloudflare Dashboard.

PS: I found a comment by James on this very issue, but his solution was hidden by the fold of comments GitHub shows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
app router This issue is related to the App router blocked by external This can't be currently solved because of external factors (Vercel/Next, Pages, etc...) bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.