Uncaught ReferenceError: MessageChannel is not defined
Updating different (unrelated) dependencies causes this. At least some seem to be related to React19 (which itself also causes this 🥲
I'm not sure it's directly CF related tho it only happens on
wrangler deploy
and only after building etc 🤔
Update: nodejs_compat
is already enabled in my wrangler.toml14 Replies
Hello! Same issue here
I am using pages and workers, I am getting this same issue
Are you using astro? or just apis?
An easy fix: just take your package.json to the previous configuration when it was working 🤣 And it really worked
but, do this at your own risk, because using unupdated packages is generally considered a security vulnerability
Anyways, I ain't from cloudflare, I am just someone like you getting errors and trying to fix them, lets wait for someone from cloudflare to reply
Yea this is working for me for now as well, it started to happen only with react 19, all other packages on latest, now it seems like as packages start to officially support react 19 they cause the same issue so now I have lots of outdated packages 🥲
Surprising that seemingly no one else seems to run into this so far 🤔
the code throwing error
GitHub
Bug: Uncaught ReferenceError: MessageChannel is not defined · Issue...
React version: 19.0.0 Steps To Reproduce Create an Astro & React project with server adapter for Cloudflare Try to deploy to Cloudflare Pages via wrangler deploy The current behavior Uncaught R...
nice, thank you for finding and reporting 🙏
Would love a solution to this!
It looks like someone else hit the unsupported
MessageChannel
API in Vercel's Edge Runtime https://github.com/vercel/next.js/issues/60337 but this is the only issue I can find & it was never resolved, so they might still not support it. Not sure if this is in the scope for workerd or if React should revert its usage.GitHub
Next.js 14.0.4 - Edge Runtime Warnings in scheduler Module · Issue ...
Link to the code that reproduces this issue https://github.com/Soheiljafarnejad/sabzlearn-front To Reproduce I am encountering warnings related to the use of Node.js APIs in the scheduler module wh...
@Mike Nomitch | Workers PM hi 👋 would opening an issue on workerd be appropriate for this?
@jado I think it is the React issue as MessageChannel is for the browsers only (or browser context).
mm i see
Hey @jado sorry for the slow reply on this.
I won't have time to fully dig in today, but I think even if its a React issue, it's worth opening a workerd issue for this. Others might hit it so good for redirecting them to open React issues, and its good evidence that supporting that API is valuable (even if an upstream changes it later).
@Radoš so this is server-side React code that gets executed assuming MessageChannel is there? You sure its React and not Astro or the CF-specific code for that integration?
GitHub
🐛 Bug Report — Runtime APIs: MessageChannel · Issue #3273 · cloudfl...
The MessageChannel API is available on node but not CF Workers. This is causing an issue during the deployment of sites using React 19 + Astro + Workers, see facebook/react#31827 and withastro/astr...
ah this is an issue with astro not using the edge renderer, workaround is here: https://github.com/withastro/adapters/pull/436#issuecomment-2525190557
GitHub
fix(cloudflare): use React edge renderer for compatibility with Rea...
Note: Until a proper fix gets merged, you can use this workaround.
React 19 requires MessageChannel from node:worker_threads, which isn't available in Cloudflare's workerd runtime....
this config worked for me:
In some other parts of the Rect code (similar to this one), there is condition to check if MessageChannel exists, so this is why assume it is issue there.