-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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] bug: React is not defined
in production build with Vite 3
#1693
Comments
React is not defined
in production build with Vite 3React is not defined
in production build with Vite 3
I ran into the same issue. As a workaround for now, I disabled the "automatic JSX Runtime" in vite.config.ts by setting the jsxRuntime to
|
Thanks for the hint! While this seems to work, it's odd that the automatic JSX Runtime does not work with Vite.3 anymore. |
Hey! Thank you for your bug report! This doesn't seem like a Headless UI issue and it seems that the workaround provided by @protyze works! If you are running into this issue, check out this comment: #1693 (comment) |
What package within Headless UI are you using?
@headlessui/react
What version of that package are you using?
v1.6.6
What browser are you using?
Chrome 103.0.5060.114
Reproduction URL
https://github.com/pantajoe/headless-ui-vite-disclosure-error
yarn install
to install dependencies.yarn dev
to see everything is working.yarn build
yarn serve
(see error: React is not defined)Describe your issue
Hello there 👋🏼
I love using headlessUI and I recently switched from CRA to Vite. It worked fine with Vite
2.x
, and a few days ago Vite 3 was released together with a new plugin for React. However, it seems to me as if the equality check in the Disclosure component againstReact.Fragment
results in vite bungling something upon building:headlessui/packages/@headlessui-react/src/components/disclosure/disclosure.tsx
Line 171 in e819c0a
After building my project with
yarn build
and when somwhere importingDisclosure
from@headlessui/react
, I get the following error as soon as I start the production build withyarn serve
:Reference Error: React is not defined
And the stacktrace directly points to the equality check of the
as
prop withReact.Fragment
.In the
node_modules
, I manually changed the equality check to byprops.as === Fragment
sinceFragment
is also directly imported in the file and this worked without any problem.I'm not sure how this comes to be, but since it's an easy and non-breaking fix, I would really appreciate this fix for Vite 3!
Thanks for reading and maintaining!
The text was updated successfully, but these errors were encountered: