Skip to content

fix: use the classic JSX runtime for the Vite 8 dep scan (#262) - #363

Open
brenelz wants to merge 1 commit into
mainfrom
fix/262-vite8-scan-jsx-classic
Open

brenelz wants to merge 1 commit into
mainfrom
fix/262-vite8-scan-jsx-classic

Conversation

@brenelz

@brenelz brenelz commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Fixes #262 on the 2.x line. Backport of 3257a97 (already on next / @solidjs/vite-plugin 3.0.0-next).

Problem

For Vite 8+ the plugin set optimizeDeps.rolldownOptions.transform.jsx: 'preserve' so the Rolldown scanner would not inject react/jsx-dev-runtime imports. But the scanner re-parses the transformed output as plain JS (Vite's vite:dep-scan:transform:js-glob even force-tags glob-containing modules as moduleType: 'js'), so any .tsx with JSX failed with PARSE_ERROR: Unexpected JSX expression. The whole scan aborted and pre-bundling was skipped:

(!) Failed to run dependency scan. Skipping dependency pre-bundling. Error:   Failed to scan for dependencies from entries:
  .../index.html
  [PARSE_ERROR] Unexpected JSX expression
   ╭─[ src/bug.tsx:4:9 ]

Fix

Use the classic JSX runtime for the scan transform (jsx: { runtime: 'classic' }). It lowers JSX to bare React.createElement calls without injecting any import; the scan output is never executed, it only exists so rolldown can walk the import graph, so the undefined identifier is harmless.

Note for anyone testing locally: the string form jsx: 'classic' (as tried in the issue thread) is not a valid rolldown option and fails with Invalid jsx option. It has to be the object form.

Verification

Packed this branch (pnpm pack) and installed the tarball in a minimal project (vite 8.3.0, solid-js 1.9.15) with a .tsx that calls import.meta.glob and returns JSX:

  • Published 2.11.14: vite optimize --force and vite dev fail with the parse error above.
  • This branch: vite optimize --force pre-bundles solid-js, solid-js/web, solid-js/store, solid-js/html, solid-js/h; the dev server serves the file with the glob expanded; vite build succeeds.

🤖 Generated with Claude Code

Backport of 3257a97 from next. `jsx: 'preserve'` in
optimizeDeps.rolldownOptions.transform was self-defeating: the scanner
re-parses the transformed output as plain JS (the js-glob transform
force-tags glob-containing modules as moduleType js), so any .tsx with
JSX failed with PARSE_ERROR: Unexpected JSX expression, the whole scan
aborted and pre-bundling was skipped. The classic runtime lowers JSX to
bare React.createElement calls without injecting an import; the scan
output is never executed, so the undefined identifier is inert.

Verified with a packed tarball against vite 8.3.0 + solid-js 1.9.15:
`vite optimize`, the dev server and `vite build` all succeed on a .tsx
file that uses import.meta.glob.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Sep 18, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 8909380

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
vite-plugin-solid Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Sep 18, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/vite-plugin-solid@363

commit: 8909380

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

jsx: 'preserve' in optimizeDeps breaks dependency scan when .tsx files use import.meta.glob

1 participant