You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 17, 2022. It is now read-only.
I get an Uncaught ReferenceError: React is not defined error, when rendering the DateTimePicker component from @material-ui/pickers. This error happens only in production build and not in the dev server.
Everything seems to be transpiled correctly when processing the vendor-bundle, except the React.Fragment reference.
Final code:
return react.exports.createElement(React.Fragment, null ....
In my bundle, Fragment is defined as ua, and this line should probably have been:
return react.exports.createElement(Ra('ua'), ....)
Where Ra is a function that returns different types, ex Fragment. (Trying to read minfied stuff is not that easy, so i might be mistaken about the exact reference it should have had. But React.Fragment shouldnt have leaked directly into the vendor-bundle after being built by vite/esbuild.
I have the same issue using @vitejs/plugin-react with react-custom-scrollbars/react-custom-scrollbars-2. The issue there seems to be that it is using React.createElement instead of _react3 which is used in other calls.
In the output generated it creates variable var _react3 = react.exports; which is used for the Component and cloneElement from the imports in react-custom-scrollbars-2. But the createElement function is not using this var and calls React.createElement. Has anyone encountered this? It seems to be the same issue @thsorens is experiencing with React.Fragment reference not beign transpiled correctly.
I ran into the same issue. Like others, I suspect the culprit package is @material-ui/pickers. I was able to fix this by choosing the "classic" option for the jsxRuntime in the react plugin definition. I'll probably upgrade to material v5 at some point. That seems to fix other issues I have been having.
Hi guys, we also ran into this issue with @chakra-ui and chakra-ui-steps.
Can any one provide an advice how to handle this, using option runtime classic does not help, also the older versions
if anyone can provide some guidance would be great.
thx
edit after couple of hours of playing with it, found config that actually works, but would love to no why is @vitejs/react-plugin not needed for production build. Also how to identify library that is not supported by vite.
import{defineConfig}from'vite';import{resolve}from'path';importreactfrom'@vitejs/plugin-react';// https://vitejs.dev/config/exportdefaultdefineConfig(({ mode })=>({build: {outDir: 'build'},plugins: [react()],resolve: {alias: [{// This template is using src/ imports, so we changed itfind: 'src',replacement: resolve(__dirname,'src')}]}}));
Activity
callmeberzerker commentedon Jul 27, 2021
Yes I am experiencing the same issue exactly with
@material-ui/pickers
callmeberzerker commentedon Jul 27, 2021
I created the following issue as well, because I am not certain who is causing it. mui/material-ui#27473
aleclarson commentedon Sep 22, 2021
Can you see if this issue is fixed by using
@vitejs/plugin-react
?aykxt commentedon Sep 23, 2021
Unfortunately the issue persists there too.
thsorens commentedon Oct 28, 2021
Calendar.prototype.render = function () { var _a = this.state, currentMonth = _a.currentMonth, slideDirection = _a.slideDirection; var _b = this.props, classes = _b.classes, allowKeyboardControl = _b.allowKeyboardControl, leftArrowButtonProps = _b.leftArrowButtonProps, leftArrowIcon = _b.leftArrowIcon, rightArrowButtonProps = _b.rightArrowButtonProps, rightArrowIcon = _b.rightArrowIcon, loadingIndicator = _b.loadingIndicator; var loadingElement = loadingIndicator ? loadingIndicator : React.createElement(CircularProgress_1.default, null); return (React.createElement(React.Fragment, null, allowKeyboardControl && this.context !== 'static' && (React.createElement(KeyDownListener, { onKeyDown: this.handleKeyDown })), React.createElement(CalendarHeader_1.default, { currentMonth: currentMonth, slideDirection: slideDirection, onMonthChange: this.handleChangeMonth, leftArrowIcon: leftArrowIcon, leftArrowButtonProps: leftArrowButtonProps, rightArrowIcon: rightArrowIcon, rightArrowButtonProps: rightArrowButtonProps, disablePrevMonth: this.shouldDisablePrevMonth(), disableNextMonth: this.shouldDisableNextMonth() }), React.createElement(SlideTransition_1.default, { slideDirection: slideDirection, transKey: currentMonth.toString(), className: classes.transitionContainer }, React.createElement(React.Fragment, null, (this.state.loadingQueue > 0 && (React.createElement("div", { className: classes.progressContainer }, loadingElement))) || React.createElement("div", null, this.renderWeeks()))))); };
Everything seems to be transpiled correctly when processing the vendor-bundle, except the React.Fragment reference.
Final code:
return react.exports.createElement(React.Fragment, null ....
In my bundle, Fragment is defined as ua, and this line should probably have been:
return react.exports.createElement(Ra('ua'), ....)
Where Ra is a function that returns different types, ex Fragment. (Trying to read minfied stuff is not that easy, so i might be mistaken about the exact reference it should have had. But React.Fragment shouldnt have leaked directly into the vendor-bundle after being built by vite/esbuild.
Pernick commentedon Nov 10, 2021
I have the same issue using
@vitejs/plugin-react
withreact-custom-scrollbars
/react-custom-scrollbars-2
. The issue there seems to be that it is usingReact.createElement
instead of_react3
which is used in other calls.react-custom-scrollbars-2
is importing React helper functions here:https://github.com/RobPethick/react-custom-scrollbars-2/blob/master/src/Scrollbars/index.js#L3
In the output generated it creates variable
var _react3 = react.exports;
which is used for theComponent
andcloneElement
from the imports inreact-custom-scrollbars-2
. But thecreateElement
function is not using this var and callsReact.createElement
. Has anyone encountered this? It seems to be the same issue @thsorens is experiencing withReact.Fragment
reference not beign transpiled correctly.luxferrew commentedon Dec 29, 2021
@Pernick
Maybe I find the solution...
I tried any solution ways in other similar issue(in material-ui vite rollup vitejs/plugin-react ....) but it not work.
then... I find a suspicious point in the plugin
@vitejs/plugin-react
, src/index.tsx:const importReactRE = /(^|\n)import\s+(\*\s+as\s+)?React(,|\s+)/
this RegE can not match the
React__default
in the@material-ui/pickers/esm/CalendarXXX
file(if you're using material-ui@v4).I try this vite config(resolve.alias):
to replace
esm
file, and work well .Maybe your problems could use the same way like this. Just pay attention to the vitejs/plugin-react(if you use...)
ChuckJonas commentedon Jan 7, 2022
I get this same issue, but in my dev build...
@vitejs/plugin-react@1.1.4
:ReferenceError: React is not defined
when rendering a Dialog-component from@mui/material
vitejs/vite#6537seanmthompson commentedon Feb 2, 2022
Im having this issue as well...
lempira commentedon Feb 9, 2022
I ran into the same issue. Like others, I suspect the culprit package is @material-ui/pickers. I was able to fix this by choosing the "classic" option for the jsxRuntime in the react plugin definition. I'll probably upgrade to material v5 at some point. That seems to fix other issues I have been having.
The fix
My deps for reference:
marek-sed commentedon Feb 21, 2022
Hi guys, we also ran into this issue with @chakra-ui and chakra-ui-steps.
Can any one provide an advice how to handle this, using option runtime classic does not help, also the older versions
the failing example is here.
https://stackblitz.com/edit/vitejs-vite-syu3ve?file=src/App.tsx
if anyone can provide some guidance would be great.
thx
edit after couple of hours of playing with it, found config that actually works, but would love to no why is @vitejs/react-plugin not needed for production build. Also how to identify library that is not supported by vite.
FreddyAilogic commentedon Apr 20, 2022
I had the same problem, after migrating from CRA to Vite, still unable to solved:
tsconfig.json
vite.config.ts
package.json
6 remaining items