Conversation
The Vitest setup-file check used the plugin's own `require`, so it asked whether vite-plugin-solid could reach `@testing-library/jest-dom/vitest`. Under pnpm's isolated layout that succeeds when another package (e.g. Storybook) depends on jest-dom transitively, but Vitest resolves `setupFiles` from the project root, where the package is not installed, and fails with "Failed to load url .../@testing-library/jest-dom/vitest". Probe from the project root instead so the setup file is only injected when the project itself can resolve it. The bare specifier is still what gets injected: the resolved path would be jest-dom's CommonJS entry, which Vitest refuses to load. Fixes #231 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 6cc30fe The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
commit: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #231
Problem
getJestDomExportused the plugin's ownrequire(created fromimport.meta.url), so the check was "can vite-plugin-solid reach@testing-library/jest-dom/vitest?". With pnpm's isolatednode_modulesthat is true whenever another package in the tree (Storybook in the issue) depends on jest-dom transitively, because pnpm links the optional peer next to the plugin. Vitest, however, resolves baresetupFilesspecifiers from the project root, where@testing-library/jest-domis not installed, so the injected setup file fails withFailed to load url .../@testing-library/jest-dom/vitest.Fix
Probe with a
requirecreated from the project root (userConfig.root, falling back toprocess.cwd()), so the setup file is only injected when the project itself can resolve jest-dom. That matches the intent of an optional peer dependency: you opt in by installing it.The bare specifier is still what gets injected. I tried injecting the resolved absolute path as extra hardening, but
require.resolvepicks jest-dom's CommonJS entry (dist/vitest.js), which Vitest rejects with "Vitest cannot be imported in a CommonJS module using require()". Vitest resolving the specifier itself lands on the ESM entry. There is a comment explaining this next to the code.Verification
confighook withmode: 'test'from a Node script. Withrootset to this repo (jest-dom installed) it injects@testing-library/jest-dom/vitest; withrootset to an empty project it injects nothing, even though the plugin itself can still resolve jest-dom. That second case is the issue's scenario.examples/vite-7againstsrc/index.tsassertingexpect(null).toBeInTheDocumentis a function. It passes, so the injected setup file loads.🤖 Generated with Claude Code