fix(vite-builder): tolerate ENOENT when deleting empty directories - #2534
Merged
Conversation
…plugin writes removeEmptyDirs() walks outDir with readdir() then stat()s each entry. If another plugin (eg. vite-plugin-static-copy) writes into outDir around the same build hook, a file can be renamed/removed between the two calls, throwing ENOENT and failing the whole build intermittently. Fixes wxt-dev#2533
✅ Deploy Preview for creative-fairy-df92c4 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
@wxt-dev/analytics
@wxt-dev/auto-icons
@wxt-dev/browser
@wxt-dev/i18n
@wxt-dev/is-background
@wxt-dev/module-react
@wxt-dev/module-solid
@wxt-dev/module-svelte
@wxt-dev/module-vue
@wxt-dev/runner
@wxt-dev/storage
@wxt-dev/unocss
@wxt-dev/webextension-polyfill
wxt
commit: |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2534 +/- ##
==========================================
- Coverage 79.24% 79.13% -0.12%
==========================================
Files 131 133 +2
Lines 3975 3982 +7
Branches 913 923 +10
==========================================
+ Hits 3150 3151 +1
- Misses 731 735 +4
- Partials 94 96 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
aklinker1
approved these changes
Jul 31, 2026
Member
There was a problem hiding this comment.
New tests look good, we can point people to your writeup instead of having a large comment.
Checks are probably going to fail because of formatting, run bun check in the project root and it will be fixed.
Edit: yup, and some typos
7 Problems:
⚠ Not formatted.
→ ./packages/wxt/src/core/builders/vite/__tests__/remove-empty-dirs.test.ts
✗ Unknown word (oleks)
→ ./packages/wxt/src/core/builders/vite/__tests__/remove-empty-dirs.test.ts:9:32
✗ Unknown word (oleks)
→ ./packages/wxt/src/core/builders/vite/__tests__/remove-empty-dirs.test.ts:46:97
✗ Unknown word (racey)
→ ./packages/wxt/src/core/builders/vite/__tests__/remove-empty-dirs.test.ts:50:10
✗ Unknown word (racey)
→ ./packages/wxt/src/core/builders/vite/__tests__/remove-empty-dirs.test.ts:51:20
✗ Unknown word (racey)
→ ./packages/wxt/src/core/builders/vite/__tests__/remove-empty-dirs.test.ts:57:18
⚠ Not formatted.
→ ./packages/wxt/src/core/builders/vite/index.ts
ENOENT when moving HTML files
ENOENT when moving HTML filesENOENT when deleting empty directories
2 tasks
- Run `bun check` to fix formatting (single quotes, 2-space indent), matching the rest of the repo's style - Shorten the ENOENT-handling comment per review suggestion, pointing to the issue writeup instead of a large inline explanation - Drop the private oleks/mcp-chrome#61 reference and rename the cspell-flagged `raceyFile` variable
aklinker1
enabled auto-merge (squash)
August 1, 2026 14:38
Contributor
|
Thanks for helping make WXT better! |
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.
What
removeEmptyDirs()(inpackages/wxt/src/core/builders/vite/index.ts) walksoutDirwithreaddir()thenstat()s each entry to find directories to recurse into. If another plugin writes intooutDiraround the same build-hook lifecycle point — in my casevite-plugin-static-copyonhook: 'writeBundle'— a file can be renamed or removed between thereaddir()and thestat()call on that specific entry, throwingENOENTand failing the entire build intermittently.This fixes that by catching
ENOENTfromstat()and skipping that entry (it can't be a directory we need to recurse into if it no longer exists), rather than letting the error propagate.Context
Full root-cause writeup, including how I traced this and ruled out a couple of other candidate causes (cross-entrypoint-group parallelism, a
writeBundle→closeBundlehook-ordering fix): #2533Testing
Added
packages/wxt/src/core/builders/vite/__tests__/remove-empty-dirs.test.tswith two cases:readdir()andstat()no longer throwsI wasn't able to run the full local build/test suite for this change (constrained dev environment), so please let CI be the actual verification here — happy to iterate on review feedback.