fix: ignore paths.base under Vitest to avoid vite-node module resolution failures#15715
Open
MukundaKatta wants to merge 1 commit intosveltejs:mainfrom
Open
fix: ignore paths.base under Vitest to avoid vite-node module resolution failures#15715MukundaKatta wants to merge 1 commit intosveltejs:mainfrom
MukundaKatta wants to merge 1 commit intosveltejs:mainfrom
Conversation
…ion failures When kit.paths.base is a prefix of the project's filesystem path (e.g. "/Users"), Vite strips that prefix from vite-node's HTTP module URLs, breaking module resolution with ERR_MODULE_NOT_FOUND. Force base to '/' when process.env.VITEST is set. Fixes sveltejs#13737
🦋 Changeset detectedLatest commit: 6c1fc6c 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 |
Contributor
|
This sounds like a bug that should be fixed in |
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.
Description
Fixes #13737.
When
kit.paths.baseis set to a value that happens to be a prefix of the project's filesystem path (e.g.base: "/Users"on macOS, orbase: "/home"on Linux), running Vitest fails with errors like:Cause
In non-build mode, the Vite plugin sets
base: kit.paths.base. vite-node fetches modules over HTTP using absolute filesystem paths as URLs. Vite strips the configuredbaseprefix from those URLs, so when the project path starts with that prefix the resulting URL no longer resolves to a real file.Fix
When
process.env.VITESTis set, forcebaseto/so vite-node's filesystem URLs are left intact. This matches the intent of the existingorder: 'pre'treatment on the config hook (added for Vitest compatibility in #15623) — Vitest doesn't overridebaseitself, so kit has to opt out.Reproduction
Clone https://github.com/neknalb/vitest-base-path-bug and run
npm test— fails onmain, passes with this change.Changesets