JSX runtime bundled incorrectly when running browser tests #7294
Labels
feat: browser
Issues and PRs related to the browser runner
p3-minor-bug
An edge case that only affects very specific usage (priority)
Describe the bug
I want to write a TypeScript web application which uses a JSX web frontend framework. JSX frameworks usually provide two entry-points, one for the framework as a library and one for the framework as a jsx-runtime which is referenced in the
tsconfig.json
like this:The JSX runtime is then automatically imported as
jsx-framework-of-the-day/jsx-runtime
. This cannot be changed but this should usually not be a problem because the JSX framework can simply point this export to the same script as the main export in the package.json:All this works fine during runtime and also with Vite, but it doesn't work with Vitest unfortunately. Vitest bundles the JSX framework runtime into a different bundle, so types which are shared by the framework library and the JSX runtime are duplicated and instanceof checks are not working.
Reproduction
For reproduction I created a minimal useless JSX framework-of-the-day and a small demo using this framework. The NPM module of the framework is referenced as a tarball in the demo project because I don't want to publish it to the NPM registry. Just assume it would be a normal NPM dependency.
Clone and prepare demo project:
Start the web application with
npm start
and open it in browser to validate that it works (PrintsWorks!
on the page). This uses Vite without any custom config. So no problem with Vite itself.Run unit tests with
npm test
. They will fail because the component created by the JSX framework cannot be rendered by therender
method of the frameworks main library because it does not recognize the type.My dummy JSX framework prints a console message when it is imported, together with the import URL, and this demonstrates the actual problem:
This shows that vitest bundles the JSX framework twice, which breaks the framework.
EDIT: Sometimes the test may succeed by repeatedly running vitest. It breaks again when clearing the cache in
node_modules/.vite
.System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: