-
Notifications
You must be signed in to change notification settings - Fork 546
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
Support useEvent (async context) in cloudflare workers #1943
Labels
Comments
pi0
changed the title
Error 500 Nitro request context is not available. Note: This is an experimental feature and might be broken on non-Node.js environments.
Support useEvent (async context) in cloudflare workers
Dec 21, 2023
Hi. Support is on the way! (https://github.com/unjs/unenv?tab=readme-ov-file#cloudflare - to be integrated soon with Nitro!) |
2 tasks
This is how you can currently enable async context for cloudflare worker deployments: nitro.config: export default defineNitroConfig({
compatibilityDate: '2025-01-01',
experimental: {
asyncContext: true,
},
unenv: {
external: ["node:async_hooks"],
},
}); wrangler.toml: compatibility_flags = [ "nodejs_als" ] #2949 + cloudflare/workers-sdk#7442 will allow Nitro to enable support out of the box. |
1 task
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Environment
Nitro 2.8.0
Nodejs: 20 (on my windows 11), but, in production, using Cloudflare pages preset while building my app.
Reproduction
Using
useEvent()
directly instead of explicitly passing inevent
gives this error:500 Nitro request context is not available. Note: This is an experimental feature and might be broken on non-Node.js environments.
Describe the bug
Of course, Cloudflare is not node environment, so the error is logical and clearly states this. But, is there any way can we have this feature in non-node environment? I mean is it actually possible? Else I will simply have to keep passing event in each function in the
utils
folder. Thanks.Additional context
Currently, the Nitro docs say:
Also, these are the docs for Async Local Storage option in Cloudflare. https://developers.cloudflare.com/workers/runtime-apis/nodejs/asynclocalstorage/#caveats. Do these caveats prevent Nitro from adding this feature in Cloudflare Pages preset?
Logs
No response
The text was updated successfully, but these errors were encountered: