Support useEvent (async context) in cloudflare workers
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 11.2k
- Forks
- 899
- Avg merge
- 2d 24m
- Merged PRs (30d)
- 40
Description
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 in event 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
- https://nitro.unjs.io/guide/utils#experimental-composition-api
- https://developers.cloudflare.com/workers/runtime-apis/nodejs/asynclocalstorage/
Currently, the Nitro docs say:
This feature is currently supported for Node.js and Bun runtimes and also coming soon to other presets that support AsyncLocalStorage interface.
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with Nitro's experimental composition API documentation for useEvent() and the Cloudflare Pages preset, then review the linked Cloudflare AsyncLocalStorage caveats. Determine whether request context can be supported in this non-Node.js runtime; done means useEvent() works without explicitly passing event, or the limitation is documented with a clear reason.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- node.js, typescript
- Domain
- backend, cloud
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100