Error: Some functionality, such as asynchronous I/O, timeouts, and generating random values,...
Runs fine on local deployment with edge configurations, i'm not quite sure why i'm encountering this error with cloudflare pages.
35 Replies
:0
MY SAVIOR IS HERE
Afraid not haha, I'm not sure what the cause might be
Please could you open an issue on the next-on-pages repository on GitHub for this issue. If possible, it would be very much appreciated if a reproduction could be provided along with it.
cries
Just please try and provide as much information about your project as possible, or a reproduction 🙏🏻. It might be caused by a dependency doing something in the global scope, but hard to say without being able to dig in
What confuses me if, its build and publishes.
I am doing stuff in the global scope
Oh yep, that's it
Soo I guess
Don't do this at all?
Yeah, you should try and move it to happen at request-time instead
I'll go ahead and try to figure out how to rewrite this without global scope...
Im still new to typescript
And this example was given to me
But, hey were going somewhere!
Yeah, I mean, that would probably be useful to use in a next.js nodejs server, but it wouldn't be that helpful in a serverless environment. The idea behind writing the realm client like that is so it would only be instantiated once, which works well for lifelong nodejs servers, but in a serverless environment where everything exists for the duration of the request, well, the effect isn't really quite the same
Sadly, I can't get mongodb to work in the edge runtime any other way @Better James
To my currently level of knowledge
Made the changes, heres to hoping :>
Also happy 4th of july @Better James
I'm British 😠
OH NO
Im sorry!
Here's an old example that you might be able to take some inspiration from - https://github.com/mongodb-developer/cloudflare-worker-rest-api-atlas/blob/main/src/index.ts
Same results.
This is all I did.
Is there a way to run a fake cloudflare pages environment on my pc @Better James ?
Some users have described this.
But i'm unsure of where I would even begin to try messing arround with those options.
That's basically the same as what you had before. In the example above, they're doing it at request time
oh and yeah,
npx wrangler pages dev .vercel/output/static --compatibility-flag=nodejs_compat
any other specific params?
you have to build it with
npx @cloudflare/next-on-pages
first 😛thx
Could help me understand why this doesn't work on run time? Is it because of the promise?
I believe so
Is their a work arround for this kind of stuff?
Cause, I would need to wait for the connection to succeed before doing anything else?
When building, I have encountered another issue....
@Better James
/search
is a static pageAre you using Windows?
I believe that's a bug with the Vercel CLI when using Windows. It stopped happening to me once I switched to Ubuntu via WSL
oh
time to use wsl
Do you think its cause of this..
the lambda route error? nah, that's just a windows bug in the vercel cli that i've encountered many times
wouldnt be able to tell you what causes it, other than using windows lol
I'm loosing my mind with this bug. I can't seem to find any solution at all anywhere
Hey, do you know if the edge runtime at vercel is different from cloudflare pages?
With vercel, i'm able to use the stock mongodb library, but in cloudflare pages, im unable to run or utilize it.
Vercel's edge deployments are run on Cloudflare Workers through their infra using Workers for Platforms. Differences between how they work will be due to either how we process stuff, or any additional work they do before running the function.
Is it the code you send above that is running on Vercel successfully?
So actually
I changed the code above to mongodb's driver instead
It works locally
And on vercel
but on cloudflare pages, it screams I need to have
export const runtime = 'edge';
When using this, the default driver doesn't work anymore.If it's not on the edge runtime, Vercel is deploying it to nodejs Lambda, not Workers with the edge runtime
I just want to get mongodb to work in the ya boi, back at it again @Better James
I'm trying to figure out what it is, I need to do, to get this to work.