-
-
Notifications
You must be signed in to change notification settings - Fork 119
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
[@vitejs/plugin-react] Don't apply automatic jsx runtime to dependencies #17
Comments
Nice going with debugging that, I got the same issue.
This actually sounds like a bug. But the comment there gives the impression it's not since it seems to actively ( I can't say if that's necessary, I mean it could be since you can't know what output bundled dependencies have. But your take on it to be able to opt out of it makes a whole lot of sense. |
"By default, the plugin uses the automatic JSX runtime. However, if you encounter any issues, you may opt out using the jsxRuntime option." So setting
Should basically do the same thing. I do however think they should make it more granular, so that you can specify which packages you want to opt out from using the automatic jsx runtime. |
@sorenhoyer yes you can use the classic runtime to disable the behaviour but I think that defeats the purpose in the case that you want to change The issue I'm trying to get at here is not that the automatic runtime is enabled by default but that the dependencies are being transformed from the classic runtime to use the automatic runtime when I do not need/expect them to be. |
@MarcPorciuncula my bad. You're absolutely right. :-) |
Closing as the classic-runtime-to-automatic-runtime transforming feature ( |
Description
I am using
@vitejs/plugin-react
with thejsxImportSource
option to automatically apply the@emotion/react
jsx transform.It seems that currently the vite-react plugin attempts to transform dependencies that use the classic runtime to use the automatic runtime and adds an import to the supplied
jsxImportSource
(ie.import ... from '@emotion/react/jsx-runtime
) into those dependencies.In my project, there is a dependency that is being transformed to use the automatic runtime but it does not have access to import from
@emotion/react
due to the node modules directory structure (I'm using pnpm which is stricter on dependency access). Because of this, I get a build error:It also seems to do this regardless of the include/exclude filter options that can be passed to the plugin.
Suggested solution
This could be fixed if there was a way to disable the behaviour of upgrading the classic jsx runtime to the automatic jsx runtime in dependencies. Probably via some option in the vite-react plugin (
{ upgradeJsxRuntimeInDependencies: false }
or similar).It might be nice to also mention that the plugin does this in the readme for the plugin as it does affect dependency code that you might not otherwise expect to be targeted by the plugin, even when you specify a filter.
Alternative
No response
Additional context
Code in the react plugin that transforms dependencies:
https://github.com/vitejs/vite/blob/0cbb33bade1b10c1503f47f8f8ed6e3b39818066/packages/plugin-react/src/index.ts#L219-L233
Note I was able to get my code to compile by manually editing the plugin and replacing line 227-230 with
const [restoredAst, isCommonJS] = [null, false]
, avoidingrestoreJSX
altogether.Validations
The text was updated successfully, but these errors were encountered: