Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vite: Don't crash with virtual module dependencies #16780

Merged
merged 4 commits into from
Feb 25, 2025

Conversation

philipp-spiess
Copy link
Member

@philipp-spiess philipp-spiess commented Feb 24, 2025

Fixes #16732

If we can not get the mtime from a file, chances are that the resource is a virtual module. This is perfectly legit and we can fall back to what we did before the changes in 4.0.8 (which is to rebuild the root every time a change contains a dependency like that).

Test plan

Added a test to mimic the setup from the repor in #16732. Also ensured the repro now passes:

Screenshot 2025-02-24 at 17 29 38

Note that importing virtual modules directly in CSS does not work as the resolver we use does not resolve against the Vite runtime it seems. This is unrelated to the regression added in 4.0.8 though and something to look into in the future.

@philipp-spiess philipp-spiess changed the title Vite: Handle missing mtime Vite: Don't crash with virtual module dependencies Feb 24, 2025
@philipp-spiess philipp-spiess marked this pull request as ready for review February 24, 2025 16:44
@philipp-spiess philipp-spiess requested a review from a team as a code owner February 24, 2025 16:44
if (stat.mtimeMs > mtime) {
return true
}
} catch {
Copy link
Member Author

@philipp-spiess philipp-spiess Feb 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a catch here as well, pretty sure deleting a dependency right now is no bueno 😅

@philipp-spiess philipp-spiess merged commit 59e003e into main Feb 25, 2025
5 checks passed
@philipp-spiess philipp-spiess deleted the fix/vite-virtual-modules branch February 25, 2025 10:30
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.

[v4] 4.0.8 Vite plugin breaks if there are virtual imports like unfonts.css
2 participants