You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm bundling a library from one repo (ES module) with Vite and importing it in another repo handled by Vite.
We have several external dependencies in this project.
In the bundled library code there are pieces of code where the React.createElement have component name in variables with lower case name and expressions, like:
When this check fails the snippet is not replaced in the original code.
Another related issue is that when we have some React aliases and the aliases are used to execute createElement (for example rollup define “React__default” when in the same file there are multiple name conflicts ) the lines:
Is going to replace the alias with React, If then the check of a valid React.createElement fails (issue above) then the plugin is not going to replace back the alias, adding in the chunk code a reference to a variable (React) that doesn’t exists.
So the issues:
There are limitations in the way that the Plugin can recognise the React.createElement snippet and that can be problematic in project with many 3rd party dependencies
When React has aliases and they are used with “createElement” if the plugin does not recognise the “React.createElement” snippet then the aliases are not replaced back
Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/core instead.
This PR vitejs/vite#6838 ( vitejs/vite#6537 ) is partially solving this problem, but not completely.
I run the reproduction example project on Vite 2.9.7 and Vite React Plugin 1.3.2 and I still see React.createElement code that has not been replaced back with the alias.
For example: React.createElement(_default$3, { src: svgSource });
This screenshot is a code fragment after the third-party dependency is packaged. After the video-plugin-react processing, the _react is changed to React. And then it caused React is not defined.
Describe the bug
I'm bundling a library from one repo (ES module) with Vite and importing it in another repo handled by Vite.
We have several external dependencies in this project.
In the bundled library code there are pieces of code where the
React.createElement
have component name in variables with lower case name and expressions, like:When I used the library executing
vite build
those expressions are not converted to_jsx
, launching an error in production, "React is undefined"After an investigation I noticed the 3 cases above are not recognised as valid “React.createElement” snippet because the check at this line fails:
https://github.com/vitejs/vite/blob/274c10eb9e9451620981da808e143bc50b8c2a38/packages/plugin-react/src/jsx-runtime/babel-restore-jsx.ts#L157
When this check fails the snippet is not replaced in the original code.
Another related issue is that when we have some React aliases and the aliases are used to execute
createElement
(for example rollup define “React__default” when in the same file there are multiple name conflicts ) the lines:https://github.com/vitejs/vite/blob/274c10eb9e9451620981da808e143bc50b8c2a38/packages/plugin-react/src/jsx-runtime/restore-jsx.ts#L33-L36
Is going to replace the alias with
React
, If then the check of a validReact.createElement
fails (issue above) then the plugin is not going to replace back the alias, adding in the chunk code a reference to a variable (React
) that doesn’t exists.So the issues:
Thanks for your great work! 🎉
Reproduction
https://github.com/GlacialBoy/vite-createElement-error
System Info
Used Package Manager
npm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: