-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
Importing react/jsx-runtime breaks dev builds #6215
Comments
I think the issue is more likely with the vite react plugin, which resolves E.g. importing |
thank you |
Saved my life! Thanks~ BTW, there may not be issue, the reason is in the comment |
1 similar comment
Saved my life! Thanks~ BTW, there may not be issue, the reason is in the comment |
Why are you importing |
@aleclarson In my case, click the issue to see, I import it to wrap its |
The PR for this looks straightforward enough. Be good to get this merged. |
I tried this solution since my dependency used it and still vite fail with following message:
conf
without this I have same error as it originally reported:
do I miss something? |
For me this proposed solution works as a temporary hotfix:
Will your PR covers this issue @aleclarson? Thank you! |
|
Change the configuration of your vite.config.js import react from '@vitejs/plugin-react';
export default defineConfig({
plugins: [
react({
jsxRuntime: 'classic',
}),
]
}); ReferenceOpting out of the automatic JSX runtime
|
For React 18 aliasing Here's the vite config for React 18 and MDX v2 that worked for me: import { defineConfig } from "vite"
import react from "@vitejs/plugin-react"
export default defineConfig(async () => {
const mdx = await import("@mdx-js/rollup")
return {
optimizeDeps: {
include: ["react/jsx-runtime"],
},
plugins: [react(), mdx.default({ remarkPlugins: [] })],
}
}) |
Thank you @pomber. This worked for me, inspired by your answer. /// <reference types="vite/client" />
import reactPlugin from '@vitejs/plugin-react'
import type { UserConfig } from 'vite'
import { defineConfig } from 'vite'
// https://vitejs.dev/config/
const config = async (): Promise<UserConfig> => {
const { default: mdx } = await import('@mdx-js/rollup')
return {
plugins: [reactPlugin(), mdx({ remarkPlugins: [] })],
optimizeDeps: {
include: ['react/jsx-runtime'],
},
build: { minify: true },
}
}
export default defineConfig(config) |
I was able to reproduce it. It worked after upgrading plugin-react to 3.0.0-alpha.2. |
Describe the bug
When importing
react/jsx-runtime
, dev build breaks with the following client error:In my more complex setup I am consuming a local prebuilt library and get a more weird error message
I've found out that setting
optimizeDeps.include: ['react/jsx-runtime']
fixes this issue and in fact'react/jsx-dev-runtime'
works because@vitejs/plugin-react
adds it by default. Does it make sense to also include'react/jsx-runtime'
there?Reproduction
StackBlitz
System Info
Used Package Manager
npm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: