-
-
Notifications
You must be signed in to change notification settings - Fork 235
Description
Description
I am using @vitejs/plugin-react with the jsxImportSource 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:
Error: [vite]: Rollup failed to resolve import "@emotion/react/jsx-runtime" from "...(path to dependency)".
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
`build.rollupOptions.external`
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:
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], avoiding restoreJSX altogether.
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that request the same feature to avoid creating a duplicate.