Skip to content

fix: load the jest-dom ESM setup file on Vitest before 1.0 - #446

Open
lxsmnsyc wants to merge 2 commits into
mainfrom
fix/141-jest-dom-old-vitest-main
Open

lxsmnsyc wants to merge 2 commits into
mainfrom
fix/141-jest-dom-old-vitest-main

Conversation

@lxsmnsyc

Copy link
Copy Markdown
Member

Fixes #141 on main (1.x). next requires Vite 8, which Vitest before 1.0 cannot run, so it is not affected.

With Vitest before 1.0, the jest-dom setup file the plugin injects now loads. Before, tests failed with Cannot read properties of undefined (reading 'extend').

Cause

  • Vitest before 1.0 resolves setupFiles with require.resolve. That picks jest-dom's CommonJS dist/vitest.js, where require('vitest').expect is undefined.
  • The same crash happens without this plugin. The plugin triggers it because it injects @testing-library/jest-dom/vitest automatically.
  • Projects on Vite 3 and 4 cannot use Vitest 1.x, so they all hit it.

Changes

  • With Vitest before 1.0, the plugin injects the absolute path of jest-dom's ESM entry.
  • Vitest 1.0 and later keep the bare specifier.

Testing

  • Reproduced with Vitest 0.34.6 on Vite 4.5.14 and 5.0.12, with jest-dom 6.2.0 and 6.9.1.
  • With the fix those pass. Vitest 1.0.0, 1.2.1, 4.0.18 and 5.0.5 still pass.
  • Added a regression test that fails without the fix.
  • vitest run and tsc --noEmit pass.

Note on the first commit

main had no unit tests. The first commit adds the same Vitest setup that next uses: a root vitest.config.ts, a test:unit script, and a step in the Vitest workflow. The other main fix PRs from this batch (#112, #153, #206, #130, #141) share this exact commit, so they do not conflict on it.

🤖 Generated with Claude Code

lxsmnsyc and others added 2 commits October 19, 2026 11:34
- Add a root vitest config and a test:unit script, matching the next branch.
- Run the unit tests in the vitest workflow.
- Exclude test files from the declaration build.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
- Vitest before 1.0 resolves setupFiles with require.resolve (local-pkg 0.4), which picks jest-dom's CommonJS vitest entry. That file reads require('vitest').expect, which is undefined, and throws "Cannot read properties of undefined (reading 'extend')".
- When the project's vitest is older than 1.0, inject the absolute path of jest-dom's ESM vitest entry instead of the bare specifier.
- Vitest 1.0+ keeps the bare specifier.
- Add tests for both vitest ranges.

Fixes #141

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Oct 19, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a7ec25f

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 Oct 19, 2026

Copy link
Copy Markdown

Open in StackBlitz

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

commit: a7ec25f

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

vite-plugin-solid v2.8.3+ causes: TypeError: Cannot read properties of undefined (reading 'extend')

1 participant