Repository navigation
fix: use node_modules/.vite as cacheDir when node_modules exists - #21777
Merged
Merged
Conversation
Fallback to node_modules/.vite when the directory exists, even without package.json. This fixes caching for Deno projects with nodeModulesDir. Closes vitejs#21768
|
Is the second check necessary? It seems like it is already covered by the third check. |
- Move fs.existsSync into the fallback branch so it only runs when needed - Restructure ternary to if/else for readability - Add comment explaining the pkgDir vs resolvedRoot/node_modules distinction - Fix tests to use /tmp and pass root via inlineConfig
Contributor
Author
|
Not redundant, Restructured it to make that clearer in fd546e0, moved the |
path.resolve on Windows returns backslashes, but config.cacheDir is normalized to forward slashes. Wrap expected values in normalizePath to match on all platforms.
Contributor
Author
|
CI is green now,Ready to merge whenever convenient. Thanks for the review @bluwy! |
bluwy
previously approved these changes
Mar 13, 2026
sapphi-red
previously approved these changes
Mar 16, 2026
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.
Summary
This PR fixes issue #21768 by checking for the existence of the directory when determining the default cache directory, not just when exists.
Changes
Behavior
The cacheDir resolution now follows this priority:
config.cacheDiris explicitly set → use itpackage.jsonexists → usenode_modules/.vitein that directorynode_modulesdirectory exists → usenode_modules/.vite.vitein the project rootThis fixes caching for Deno projects that create
node_moduleswithoutpackage.json.Testing
Added two test cases:
node_modules/.viteis used whennode_modulesexists withoutpackage.json.viteis used when neitherpackage.jsonnornode_modulesexistCloses #21768