webpack/webpack · error · Error
Empty file ${name}
Error message
Empty file ${name} What it means
FileMiddleware.deserialize asks `readFile(name)` for an array of Buffers; if it returns an empty array the file contains no data at all and the function throws `Empty file <name>` (lib/serialization/FileMiddleware.js:277). This is the first of two emptiness guards and catches a wholly empty result list.
Source
Thrown at lib/serialization/FileMiddleware.js:277
size,
name,
backgroundJob:
backgroundJobs.length === 1
? backgroundJobs[0]
: /** @type {BackgroundJob} */ (Promise.all(backgroundJobs))
};
};
/**
* Restores this instance from the provided deserializer context.
* @param {FileMiddleware} middleware this
* @param {string | false} name filename
* @param {(name: string | false) => Promise<Buffer[]>} readFile read content of a file
* @returns {Promise<BufferSerializableType[]>} deserialized data
*/
const deserialize = async (middleware, name, readFile) => {
const contents = await readFile(name);
if (contents.length === 0) throw new Error(`Empty file ${name}`);
let contentsIndex = 0;
let contentItem = contents[0];
let contentItemLength = contentItem.length;
let contentPosition = 0;
if (contentItemLength === 0) throw new Error(`Empty file ${name}`);
const nextContent = () => {
contentsIndex++;
contentItem = contents[contentsIndex];
contentItemLength = contentItem.length;
contentPosition = 0;
};
/**
* Processes the provided n.
* @param {number} n number of bytes to ensure
*/
const ensureData = (n) => {
if (contentPosition === contentItemLength) {
nextContent();View on GitHub (pinned to 318421ea8a)
Solutions
- Delete the zero-byte file (and the surrounding cache directory) and rebuild.
- If using a custom `inputFileSystem`, ensure it returns `[Buffer.alloc(0)]` rather than `[]` for empty files — or avoid creating empty cache files.
- Check that no other process is truncating cache files.
- Free disk space and verify write permissions.
Example fix
// before: zero-byte cache file -> [] from readFile -> error // after // rm node_modules/.cache/webpack/<name> && yarn webpack
Defensive patterns
Strategy: fallback
Validate before calling
// Purge zero-byte files before running webpack
const fs = require('fs');
for (const f of walk(cacheLocation)) if (fs.statSync(f).size === 0) fs.unlinkSync(f); Try / catch
compiler.hooks.failed.tap('EmptyCacheGuard', (err) => {
if (/^Empty file/.test(err.message)) {
require('fs').rmSync(cacheLocation, { recursive: true, force: true });
}
}); Prevention
- Ensure builds finish writing before being killed.
- Keep disk free space above a floor.
- Use atomic write-then-rename (webpack already does; don't bypass it).
When it happens
Trigger: A cache file exists but `readFile` resolved with `[]` — zero chunks. Happens when the read pipeline returns nothing (e.g. a stream that ended before emitting data, or a stub filesystem in a host that yields no buffers).
Common situations: Memory FS or custom `inputFileSystem` returning [] on an empty file; race where the file was truncated to zero length before the read completed; an interrupted prior write left a 0-byte file that the reader hands back as no chunks.
Related errors
- Unexpected end of data
- Invalid section count ${sectionCount}
- Truncated pointer section
- Section table does not match file size
- Unexpected end of stream
AI-assisted analysis of webpack/webpack@318421ea8a (2026-08-03).
Data as JSON: /data/errors/b6330eb41fdb6b76.json.
Report an issue: GitHub.