Edge runtime causes 500 internal server error for bots
Answered
Arya posted this in #help-forum
AryaOP
Does anyone know why edge runtime suddenly throws an internal error for bots such as Googlebot or other web crawlers? I can't remove edge runtime because I need it for Cloudflare's D1 and R2 services to run.
131 Replies
AryaOP
Does anyone face the same problem?
I never faced such error, I've my apps deployed on next-on-pages
@Anay-208 | Ping in replies Can you share screenshot?
AryaOP
Not sure how can I share a screenshot with more details than this, I commented components that are using D1 queries and this is when I found out edge runtime gives a 500 error, despite the client is looking alright
I got a similar error on windows. I had to use wsl to fix the error
@Anay-208 | Ping in replies Are you on windows?
AryaOP
Yes, I'm on windows
You can use wsl and move your project inside it.
I got a similar error with next 15 on windows.
Using wsl magically fixes the issue
I got a similar error with next 15 on windows.
Using wsl magically fixes the issue
@Anay-208 | Ping in replies You can use wsl and move your project inside it.
I got a similar error with next 15 on windows.
Using wsl magically fixes the issue
AryaOP
I activated WSL before but not really familiar with it. How do I move my project there, then work on it?
@Arya I activated WSL before but not really familiar with it. How do I move my project there, then work on it?
There should be a wsl folder when you open file explorer. Move everything except node modules
I think there is a folder named like that only.
Just move it to ~ folder of wsl
Just move it to ~ folder of wsl
@Anay-208 | Ping in replies I think there is a folder named like that only.
Just move it to ~ folder of wsl
AryaOP
Doesn't seem like I can on normal circumstances
What error do you get?
AryaOP
Pretty much "need admin privileges", because when I try to move it to ~, the paste option is not lighting up
@Anay-208 | Ping in replies I think there is a folder named like that only.
Just move it to ~ folder of wsl
AryaOP
and how do I access it once it's in WSL?
You will need to install wsl extension then
And then CTRL+SHIFT+P, connect to WSL
@Anay-208 | Ping in replies And then CTRL+SHIFT+P, connect to WSL
AryaOP
I couldn't do
npm install
Delete node modules
And try again
AryaOP
it was already deleted before, tried a clean install
@Arya Click to see attachment
I think you’re using windows terminal
Delete node_modules, run wsl, and try installing again
Install nvm in wsl
and install nodejs in it
@Anay-208 | Ping in replies and install nodejs in it
AryaOP
alright, i successfully installed nvm, nodejs and
npm install
-ed and it works, one thing now is i cant run npm run dev
what error do you see?
remove
.wrangler
and try again
@Anay-208 | Ping in replies remove `.wrangler`
AryaOP
deleted it, ran the command but it just fails and creates the
.wrangler
folder again anywayYes, once it creates its not really a problem, but it still didn't work?
AryaOP
is the fact i cloned the project from github instead of copying it directly, is a problem?
@Anay-208 | Ping in replies Yes, once it creates its not really a problem, but it still didn't work?
AryaOP
then it still didn't work
try updating the wsl version
@Anay-208 | Ping in replies try updating the wsl version
AryaOP
still doesn't work
AryaOP
that's probably it
in the issue saw one person saying ubuntu 22 works
@Anay-208 | Ping in replies can you check your ubuntu version installed inw sl
AryaOP
i have ubuntu 20 currently
you'll need to update to 22
try
wsl --update
@Anay-208 | Ping in replies try `wsl --update`
AryaOP
i already updated and apparently my ubuntu now is version 22
try deleting node_modules and .wrangler and run dev again
@Anay-208 | Ping in replies try deleting node_modules and .wrangler and run dev again
AryaOP
deleted both, still didnt work
try running
reboot
then try againtry installing wrangler version
3.105.0
@Anay-208 | Ping in replies try installing wrangler version `3.105.0`
AryaOP
does it have to be specifically that version?
i updated wrangler to the latest version
which was apparently 4.0
Can you just try if that version actually works to broaden down the issue?
otherwise libc++, should fix the issue
@Anay-208 | Ping in replies otherwise libc++, should fix the issue
AryaOP
is it different than libc++1?
@Anay-208 | Ping in replies try installing wrangler version `3.105.0`
AryaOP
okay this version finally works
This is a older version, that’s why it does, if you upgrade right update this version it prob won’t work
@Arya is it different than libc++1?
I’ll check the exact name of package
@Anay-208 | Ping in replies I’ll check the exact name of package
AryaOP
okay, there's no more 500 errors, but how do i make sure it stays that way in production after i commit this?
If you’re in the older version, you can use it temporarily if it’s urgent. Because I’m not sure about the exact cause of the issue, as I never faced this.
AryaOP
i see
as long as it's stable and works, eh
but now i've got problems building application while deploying in cloudflare
sigh
@Anay-208 | Ping in replies Package json should be updated
AryaOP
now my website throws internal server errors to the client too, i dont know what went wrong
Check console
@Anay-208 | Ping in replies Check console
AryaOP
that's the thing, in development (localhost) it works perfectly without 500 errors, but after deploying it to cloudflare (https://thethirdswan.com/), it throws a text that just says internal server error
i assume it only affects pages with edge runtime (again), because when I access a static page (https://thethirdswan.com/about), it's normal
@Anay-208 | Ping in replies Check console
AryaOP
when i check console on the affected pages, it only shows a GET message error and that's it
should i bring this up to cloudflare's discord server?
@Arya should i bring this up to cloudflare's discord server?
You can try, but it’s a code related issue
Can you send code for that page
@Anay-208 | Ping in replies You can try, but it’s a code related issue
I mean as far as I’ve noticed, I never/barely really received a reply for code related issue there
And have you added env
@Arya try running
wrangler pages log tail
and then visit
@Anay-208 | Ping in replies Can you send code for that page
AryaOP
import { Box } from "@mui/material";
import { ArrowRightAlt } from "@mui/icons-material";
import BlogCard from "./ui/blogcard";
import Link from "next/link";
import Latest from "./ui/latest";
import Links from "./ui/links";
import CreateButton from "./ui/createbutton";
export const runtime = 'edge'
export default function Home() {
return (
<main>
<h2 className="text-xl text-center">
Hello! <br/>
I hope you enjoy my blogs! :)
</h2>
<CreateButton />
<div className="m-1">
<div className="md:grid grid-cols-2">
<div className="md:ml-52">
<p>Latest</p>
<Latest />
<hr className="hidden md:block"/>
<Links device="other"/>
</div>
<div className="md:ml-32 md:mr-52">
<p>Other Blogs</p>
<div className="flex flex-wrap justify-center md:block">
<BlogCard />
</div>
</div>
</div>
<Link href="/blog">
<Box component="section" sx={{p: 2, border: '1px solid gray', m: 2}}>
<p>View other blogs <ArrowRightAlt /></p>
</Box>
</Link>
</div>
</main>
);
}
@Anay-208 | Ping in replies <@1205126991804633104> try running `wrangler pages log tail`
AryaOP
in the terminal? i have been trying to run wrangler commands but the bash says "wrangler: command not found"
npm i -g wrangler
install it globally first
@Anay-208 | Ping in replies and then visit
AryaOP
[ERROR] Unknown arguments: log, tail
is it supposed to be like this?
Wrangler pages deployment tail
*
AryaOP
(error) Error: Disallowed operation called within global scope. Asynchronous I/O (ex: fetch() or connect()), setting a timeout, and generating random values are not allowed within global scope. To fix this error, perform this operation within a handler. https://developers.cloudflare.com/workers/runtime-apis/handlers/
(error) TypeError: Cannot redefine property: __import_unsupported
@Anay-208 | Ping in replies Wrangler pages deployment tail
AryaOP
those are the errors i get
Can you send your <Latest /> component, because there is something where you are fetching some data
@Anay-208 | Ping in replies Can you send your <Latest /> component, because there is something where you are fetching some data
AryaOP
import Image from "next/image";
import { getRequestContext } from "@cloudflare/next-on-pages";
import Link from "next/link";
import { dateParser } from "../lib/dateparser";
import imageFetch from "@/app/lib/imagefetch";
import { Card, CardContent } from "@mui/material";
export const runtime = 'edge'
export default async function Latest() {
const database = getRequestContext().env.DB;
const { results } = await database.prepare("SELECT * FROM Blog").all();
if (!results) {
throw new Error("No posts available!");
}
const latest = results.slice(-1)
let title: any;
let url: any;
let description: any;
let date: any;
title = latest[0].title;
url = latest[0].url;
description = latest[0].description;
date = latest[0].date;
let image = await imageFetch(`${latest[0].url}-cover`);
return (
<Link href={`/blog/${latest[0].url}`}>
<Card sx={{ boxShadow: 3 }} className="!bg-slate-400 hover:shadow-2xl m-2 w-full h-96 mx-auto">
<CardContent>
<Image
src={image}
width={350}
height={200}
alt={title}
className="m-auto"/>
<strong>{title}</strong>
<p>{description}</p>
<p>{dateParser(date)}</p>
</CardContent>
</Card>
</Link>
)
}
@Anay-208 | Ping in replies Can you share image fetch component?
AryaOP
import Image from "next/image";
import imageFetch from "../lib/imagefetch";
export default async function ImageFetch({ url }: {url: any}) {
const link = await imageFetch(`${url}-cover`)
return (
<Image
src={link}
width={150}
height={200}
key={url}
alt={url}
className="mx-auto my-1 md:relative md:float-start md:m-1"
/>
)
}
imageFetch.ts:
export default async function imageFetch(link: any) {
return await getSignedUrl(S3, new GetObjectCommand({Bucket: 'blog', Key: `${link}.webp`}), { expiresIn: 3600 })
}
@Arya import Image from "next/image";
import imageFetch from "../lib/imagefetch";
export default async function ImageFetch({ url }: {url: any}) {
const link = await imageFetch(`${url}-cover`)
return (
<Image
src={link}
width={150}
height={200}
key={url}
alt={url}
className="mx-auto my-1 md:relative md:float-start md:m-1"
/>
)
}
imageFetch.ts:
export default async function imageFetch(link: any) {
return await getSignedUrl(S3, new GetObjectCommand({Bucket: 'blog', Key: `${link}.webp`}), { expiresIn: 3600 })
}
yes, its due to s3 only I believe, it doesn't work well in edge runtime
use aws4fetch
@Anay-208 | Ping in replies use aws4fetch
AryaOP
Alright, I will try it later, will update soon
to confirm, try removing S3 and see if it builds
AryaOP
Like, avoid using S3? Technically the app still builds with S3
@Anay-208 | Ping in replies yes, its due to s3 only I believe, it doesn't work well in edge runtime
AryaOP
But why S3 only gives trouble just now?
@Arya Like, avoid using S3? Technically the app still builds with S3
No, just using aws Sdk s3
Problem is with SDK
You can use the new cloudflare workers package which allows you to use node runtime
@Anay-208 | Ping in replies You can use the new cloudflare workers package which allows you to use node runtime
AryaOP
So, should I do both solutions?
no, you can do any 1
its still in beta tho: https://opennext.js.org/cloudflare
but I still recommend aws4fetch to reduce cold starts
It’ll require additional config. You can just use aws4fetch
@Anay-208 | Ping in replies It’ll require additional config. You can just use aws4fetch
AryaOP
used aws4fetch, still getting internal server error on production site
can you check logs again?
@Anay-208 | Ping in replies Can you send BlogCard
AryaOP
import { getRequestContext } from "@cloudflare/next-on-pages";
import { dateParser } from "../lib/dateparser";
import Link from "next/link";
import ImageFetch from "./imagefetch";
import { Card, CardContent } from "@mui/material";
export const runtime = 'edge'
export default async function BlogCard() {
const database = getRequestContext().env.DB;
const { results } = await database.prepare("SELECT * FROM Blog ORDER BY date DESC LIMIT 6").all();
return results.map((page): JSX.Element => {
let title: any = page.title
let description: any = page.description;
let date: any = page.date;
let url: any = page.url;
return (
<Link href={`/blog/${page.url}`} key={`${page.title}`}>
<Card sx={{ boxShadow: 3 }} className="!bg-slate-400 hover:shadow-2xl m-2 md:w-full w-[200px] md:min-h-[150px]">
<CardContent>
<ImageFetch url={url}/>
<div className="title">
<strong>{title}</strong>
</div>
<div className="description">
<p>{description}</p>
</div>
<p>{dateParser(date)}</p>
</CardContent>
</Card>
</Link>
)
})
}
AryaOP
i read some github issue on next-on-pages and they're also having the same issue
@Arya i read some github issue on next-on-pages and they're also having the same issue
Can you send the link of the relevant issues?
Answer
AryaOP
apparently it happens on next@15.2, which is my nextjs version too
one user said downgrading to next@15.1 temporarily mitigates the errors
Hmm, you can then downgrade to
next@15.1.0
, I last faced this error with s3 API, and not terminating postgres connectionI never use the latest version atleast for few weeks of it launch(unless there is a security vulnerability), because of these types of issues
AryaOP
okay, finally
it fixed all the 500 errors after downgrading to
next@15.1
what's up with these breaking changes...
anyway, thank you for your help!
@Arya https://github.com/cloudflare/next-on-pages/issues/949
Can you mark this message as solution?