[PR #292] [MERGED] fix: ensure clientDir exists before writing _headers file #451

Closed
opened 2026-05-06 12:39:52 +02:00 by BreizhHardware · 0 comments

📋 Pull Request Information

Original PR: https://github.com/cloudflare/vinext/pull/292
Author: @Divkix
Created: 3/6/2026
Status: Merged
Merged: 3/6/2026
Merged by: @james-elicx

Base: mainHead: fix/headers-enoent


📝 Commits (1)

  • dc2e0f0 fix: ensure clientDir exists before writing _headers file

📊 Changes

1 file changed (+1 additions, -0 deletions)

View changed files

📝 packages/vinext/src/index.ts (+1 -0)

📄 Description

Summary

  • The closeBundle hook writes _headers to clientDir (dist/client/) without creating the directory first. Only distDir (dist/) is checked earlier in the hook.
  • When build cache is invalidated (e.g., chunk graph changes), dist/client/ may not exist yet, causing an ENOENT error on writeFileSync.
  • Adds fs.mkdirSync(clientDir, { recursive: true }) before the write. recursive: true is a no-op if the directory already exists, so this is safe on warm builds.

Reproduction

  1. Delete dist/ entirely (simulating cache invalidation)
  2. Run bun run build
  3. Build fails with ENOENT: no such file or directory, open 'dist/client/_headers'

Fix

Single line addition at packages/vinext/src/index.ts — ensures the directory exists before writing.

Test plan

  • Clean build (rm -rf dist && bun run build) succeeds without ENOENT
  • Warm build (re-run bun run build with existing dist/) still succeeds (no-op mkdirSync)
  • dist/client/_headers file is generated with correct cache headers

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/cloudflare/vinext/pull/292 **Author:** [@Divkix](https://github.com/Divkix) **Created:** 3/6/2026 **Status:** ✅ Merged **Merged:** 3/6/2026 **Merged by:** [@james-elicx](https://github.com/james-elicx) **Base:** `main` ← **Head:** `fix/headers-enoent` --- ### 📝 Commits (1) - [`dc2e0f0`](https://github.com/cloudflare/vinext/commit/dc2e0f0e09a3353d4684f018d0e613dcf593cd6e) fix: ensure clientDir exists before writing _headers file ### 📊 Changes **1 file changed** (+1 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `packages/vinext/src/index.ts` (+1 -0) </details> ### 📄 Description ## Summary - The `closeBundle` hook writes `_headers` to `clientDir` (`dist/client/`) without creating the directory first. Only `distDir` (`dist/`) is checked earlier in the hook. - When build cache is invalidated (e.g., chunk graph changes), `dist/client/` may not exist yet, causing an **ENOENT** error on `writeFileSync`. - Adds `fs.mkdirSync(clientDir, { recursive: true })` before the write. `recursive: true` is a no-op if the directory already exists, so this is safe on warm builds. ## Reproduction 1. Delete `dist/` entirely (simulating cache invalidation) 2. Run `bun run build` 3. Build fails with `ENOENT: no such file or directory, open 'dist/client/_headers'` ## Fix Single line addition at `packages/vinext/src/index.ts` — ensures the directory exists before writing. ## Test plan - [ ] Clean build (`rm -rf dist && bun run build`) succeeds without ENOENT - [ ] Warm build (re-run `bun run build` with existing `dist/`) still succeeds (no-op `mkdirSync`) - [ ] `dist/client/_headers` file is generated with correct cache headers --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
BreizhHardware 2026-05-06 12:39:52 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/vinext#451
No description provided.