Skip to content
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

React 19 + Cloudflare Adapter -> "Bug: Uncaught ReferenceError: MessageChannel is not defined" #12824

Open
1 task
ethanniser opened this issue Dec 24, 2024 · 1 comment
Labels
needs triage Issue needs to be triaged

Comments

@ethanniser
Copy link

Astro Info

Astro                    v5.1.1
Node                     v22.6.0
System                   macOS (arm64)
Package Manager          bun
Output                   server
Adapter                  @astrojs/cloudflare
Integrations             @astrojs/mdx
                         @astrojs/sitemap
                         @astrojs/tailwind
                         @astrojs/react

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

originally shared facebook/react#31827 but I think it makes sense to be an issue here as I doubt its a react issue

image

It doesn't happen during build but instead during the "Deploying to Cloudflare's global network" step

What's the expected result?

The error should not happen

Link to Minimal Reproducible Example

https://github.com/phase/test-astro-react19-cf-workers (thank you @phase)

Participation

  • I am willing to submit a pull request for this issue.
@phase
Copy link

phase commented Dec 26, 2024

here's a workaround withastro/adapters#436 (comment)

astro.config.mjs

// @ts-check
import { defineConfig } from "astro/config";
import cloudflare from "@astrojs/cloudflare";

import react from "@astrojs/react";

// https://astro.build/config
export default defineConfig({
  output: "server",
  adapter: cloudflare(),
  integrations: [react()],
  vite: {
    resolve: {
      // Use react-dom/server.edge instead of react-dom/server.browser for React 19.
      // Without this, MessageChannel from node:worker_threads needs to be polyfilled.
      alias: import.meta.env.PROD && {
        "react-dom/server": "react-dom/server.edge",
      },
    },
  },
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage Issue needs to be triaged
Projects
None yet
Development

No branches or pull requests

2 participants