-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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
@vitejs/[email protected]
: ReferenceError: React is not defined
when rendering a Dialog-component from @mui/material
#6537
Comments
Hello @glennbarosen. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with |
use a github repository if you can't repro against stackblitz |
I experienced the same error in production builds only. Downgrading to |
The issue seems to related to a custom MuiDialog from our component library. I will try to reproduce the problem. |
I have updated the issue with repro on stackblitz, although the issue does not seem to happen when running |
Same issue in our app. |
I'm in way over my head when it comes to this stuff, but my best(and only) bet is that the changes in (ce65c56) broke the way Vite handles our compiled MuiDialog from our component library. Related PR: (#6110) Since the issue does not happen in the repro above, I am guessing that it is a conflict between babel/vite since we are using babel in our library. |
This might be related to alloc/vite-react-jsx#10 and #5608 |
Happened to me as well, but only when running My guess it is because of this line: vite/packages/plugin-react/src/index.ts Line 192 in e6495f0
|
Hmm, so looking at other discussions of similar issues, just a hunch but I think it might be when a library explicitly uses The plugin is supposed to transform all the cases, according to the README of the plugin that was merged into the current plugin: https://github.com/alloc/vite-react-jsx Using the older @vitejs/plugin-react-refresh plugin that doesn't do the new transforms, works for me if I inject an React import (if you don't add it in components yourself) defineConfig({
plugins: [reactRefresh()],
esbuild: {
jsxInject: `import React from 'react'`,
}) |
I have the same issue in production mode and I can confirm than downgrading |
Describe the bug
When rendering a page containing a Dialog component from
@mui/material
while using @vitejs/plugin-react version1.1.4
, the app crashes with error messageReferenceError: React is not defined
. It seems to be related to the bug fix regardingReact.createElement
in the latest release.When switching version to
1.1.3
everything works as expected. Unfortunately, I was not able create an isolated reproduction of the error in StackBlitz. To reproduce, render aMuiDialog
in an app using@vitejs/plugin-react
version1.1.4
. The issue is only occuring in production builds, not dev environment.Reproduction
StackBlitz repro
System Info
Used Package Manager
yarn
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: