-
-
Notifications
You must be signed in to change notification settings - Fork 6.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
Specifying "jsxRuntime: classic" for a React vite app is not enough for "import React from 'react'" to be added to the source code in production build #7586
Comments
+1, running into the same issue. Specifically, this happens ONY during |
We also ran into this issue. We have React component files that doesn't have config is:
Works pretty well on development, but right after build it doesn't. Browser console shows: |
Describe the bug
I have created a vite app using the react-ts template. This adds the
@vitejs/plugin-react
plugin to thevite.config.ts
file. By default the automatic jsx runtime is used by the plugin but it is possible to specify the classic jsx runtime, like so:This should have the effect of adding
import React from 'react';
to the start of any jsx/tsx file in the project, if it does not already importReact
. The filesrc/App.tsx
does not importReact
but the import line does not get added to it when building the production version of the app (npm run build
).It is on this line in packages/plugin-react/src/index.ts that the
import React from 'react';
line of code is added to the value ofcode
if required.However, in a production build of the app (
npm run build
), it is possible for the subsequent shouldSkip condition to evaluate astrue
and for the function to return without doing anything with the updated value ofcode
.It seems that, in a production build of the vite app, it is only by also specifying in the
@vitejs/plugin-react
a babel configuration file or a list of babel plugins to apply that this condition will evaluate tofalse
and the updatedcode
value will be used.Reproduction
https://github.com/stevejay/vite-jsxruntime-classic-repro
System Info
Used Package Manager
npm
Logs
Uncaught ReferenceError: React is not defined
Validations
The text was updated successfully, but these errors were encountered: