plugin-react
: React
default import in node_modules
results to React is not defined
#9371
Closed
7 tasks done
Labels
p2-edge-case
Bug, but has workaround or limited in scope (priority)
Describe the bug
I am using React with Vite 3 and
@vitejs/plugin-react
together with@headlessui/react
.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:https://github.com/tailwindlabs/headlessui/blob/e819c0a7b2e2aa6de32866ea956174d2e90f2219/packages/%40headlessui-react/src/components/disclosure/disclosure.tsx#L171
After building my project with
yarn build
and when somewhere importingimport { Disclosure } from '@headlessui/react'
, I get the following error as soon as I start the production build with yarn serve:Reference Error: React is not defined
And the stacktrace directly points to the equality check of the as prop with React.Fragment.
If you look at the import statements here, you see that
Fragment
is imported fromreact
while the default export ofreact
is also imported asReact
. In the production build the usage ofFragment
seems to be fine whileReact.Fragment
is not transformed properly to point to the minified variable name ofReact
.I also opened an issue in the
headlessui
repo, but I assume that this is a bug of Vite since Vite < 3 works without any problems with@headlessui/react
.However, using the react plugin with
react({ jsxRuntime: 'classic' })
instead ofautomatic
seems to work.Reproduction
https://github.com/pantajoe/headless-ui-vite-disclosure-error
System Info
Used Package Manager
yarn
Logs
Click to expand!
Validations
The text was updated successfully, but these errors were encountered: