nitro icon indicating copy to clipboard operation
nitro copied to clipboard

Cloudflare asyncContext support, how to enable?

Open ayalon opened this issue 1 year ago • 1 comments

Describe the change

I see a lot of efforts to make the experimental feature asyncContext introduced here to work on cloudflare workers.

  experimental: {
    asyncContext: true,
  },

My code depends on this flag but unfortunatly I find no documentation / way to add support for this to may cloudflare worker application.

In wrangler.toml I have this: compatibility_flags = [ "nodejs_compat" ]

In the documentation of unjs/unenv I find no clear instruction how to use the preset. I build and deploy my application like this: NITRO_PRESET=cloudflare nuxt build

But this is obviously not enough because the application still crashing because asyncContext is not working / enabled / polyfilled.

I highly appreciate any documentation how to enable / use the preset with nuxt.

URLs

No response

Additional information

  • [ ] Would you be willing to help?

ayalon avatar Jul 04 '24 08:07 ayalon

Adding the following config might have the magic.

export default defineNuxtConfig({
  // other config...

  nitro: {
    preset: "cloudflare-pages",
    unenv: cloudflare,
    experimental: {
      wasm: true,
      asyncContext: true,
    },
  },

  // other config...
})

But it's now still having some issue for Cloudflare Pages. useEvent().context.cloudflare might sometimes be undefined

SYM01 avatar Oct 04 '24 15:10 SYM01

Please followup https://github.com/nitrojs/nitro/issues/1943#issuecomment-2573016133 for latest usage and updates.

pi0 avatar Jan 06 '25 12:01 pi0