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

Bug: Uncaught ReferenceError: MessageChannel is not defined #31827

Closed
radosek opened this issue Dec 18, 2024 · 10 comments
Closed

Bug: Uncaught ReferenceError: MessageChannel is not defined #31827

radosek opened this issue Dec 18, 2024 · 10 comments
Labels
Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug

Comments

@radosek
Copy link

radosek commented Dec 18, 2024

React version: 19.0.0

Steps To Reproduce

  1. Create an Astro & React project with server adapter for Cloudflare
  2. Try to deploy to Cloudflare Pages via wrangler deploy

The current behavior

Uncaught ReferenceError: MessageChannel is not defined

The expected behavior

Should work in the same way as latest 18 version.

https://github.com/facebook/react/blob/6a4b46cd70d2672bc4be59dcb5b8dede22ed0cef/packages/react-server/src/ReactServerStreamConfigBrowser.js#L16C1-L28C2

@radosek radosek added the Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug label Dec 18, 2024
icepuma added a commit to RawkodeAcademy/RawkodeAcademy that referenced this issue Dec 20, 2024
phase added a commit to phase/test-astro-react19-cf-workers that referenced this issue Dec 21, 2024
@phase
Copy link

phase commented Dec 21, 2024

I made a repo with the steps to reproduce this: https://github.com/phase/test-astro-react19-cf-workers

@prolanzer
Copy link

Had to downgrade to 18.x.x to make the deploy working again.

@terao-ryohei
Copy link

I made a repo with the steps to reproduce this: https://github.com/phase/test-astro-react19-cf-workers

I have same problem in my ReactRouterV7 project.
I tried fix this, and build/deploy, Then I got work in my environment.
Please check it.

122|            'astro:build:setup': ({ vite, target }) => {
123|                if (target === 'server') {
124|                    vite.resolve ||= {};
125|                   vite.resolve.alias ||= {};
126|                    const aliases = [
127|                        {
128|                            find: 'react-dom/server',
129|                           -  replacement: 'react-dom/server.browser',
129|                           +  replacement: 'react-dom/server.edge',
130|                        },
131|                    ];

In ReactRouterv7, I can fix same. (fix entry.server.tsx)
That's why I think we can't use react-dom/server.browser on React_v19 or something.

@phase
Copy link

phase commented Dec 26, 2024

That config change worked withastro/adapters#436 (comment)

Here's my full 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",
      },
    },
  },
});

icepuma added a commit to RawkodeAcademy/RawkodeAcademy that referenced this issue Dec 26, 2024
@totawe
Copy link

totawe commented Dec 26, 2024

Tota

@radosek
Copy link
Author

radosek commented Dec 27, 2024

@phase so deploy works for you? How do you deploy your codebase as wrangler pages deploy still fails for me? Thanks

@CanRau
Copy link

CanRau commented Dec 27, 2024

fantastic, had to alias react-dom/server.browser to react-dom/server.edge in my case but it works for now 👌🏼

@phase
Copy link

phase commented Dec 27, 2024

@phase so deploy works for you? How do you deploy your codebase as wrangler pages deploy still fails for me? Thanks

I'm using workers, can you try deploying there? Or are you using features that require pages? Would love to see the error and your wrangler.toml.
That config & bunx astro build && bunx wrangler deploy worked for me in my test repo.

@radosek
Copy link
Author

radosek commented Dec 28, 2024

@phase Thanks. After clearing cache several times it seems to work 🤦‍♂️

@radosek
Copy link
Author

radosek commented Dec 28, 2024

I guess this should be fixed in @astrojs/cloudflare or in both cf/react integrations.

@radosek radosek closed this as completed Dec 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug
Projects
None yet
Development

No branches or pull requests

6 participants