{"id":"b6330eb41fdb6b76","repo":"webpack/webpack","slug":"empty-file-name","errorCode":null,"errorMessage":"Empty file ${name}","messagePattern":"Empty file (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/serialization/FileMiddleware.js","lineNumber":277,"sourceCode":"\t\tsize,\n\t\tname,\n\t\tbackgroundJob:\n\t\t\tbackgroundJobs.length === 1\n\t\t\t\t? backgroundJobs[0]\n\t\t\t\t: /** @type {BackgroundJob} */ (Promise.all(backgroundJobs))\n\t};\n};\n\n/**\n * Restores this instance from the provided deserializer context.\n * @param {FileMiddleware} middleware this\n * @param {string | false} name filename\n * @param {(name: string | false) => Promise<Buffer[]>} readFile read content of a file\n * @returns {Promise<BufferSerializableType[]>} deserialized data\n */\nconst deserialize = async (middleware, name, readFile) => {\n\tconst contents = await readFile(name);\n\tif (contents.length === 0) throw new Error(`Empty file ${name}`);\n\tlet contentsIndex = 0;\n\tlet contentItem = contents[0];\n\tlet contentItemLength = contentItem.length;\n\tlet contentPosition = 0;\n\tif (contentItemLength === 0) throw new Error(`Empty file ${name}`);\n\tconst nextContent = () => {\n\t\tcontentsIndex++;\n\t\tcontentItem = contents[contentsIndex];\n\t\tcontentItemLength = contentItem.length;\n\t\tcontentPosition = 0;\n\t};\n\t/**\n\t * Processes the provided n.\n\t * @param {number} n number of bytes to ensure\n\t */\n\tconst ensureData = (n) => {\n\t\tif (contentPosition === contentItemLength) {\n\t\t\tnextContent();","sourceCodeStart":259,"sourceCodeEnd":295,"githubUrl":"https://github.com/webpack/webpack/blob/318421ea8ac81371f5171236a6efb63675576528/lib/serialization/FileMiddleware.js#L259-L295","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before: zero-byte cache file -> [] from readFile -> error\n// after\n//   rm node_modules/.cache/webpack/<name> && yarn webpack","handlingStrategy":"fallback","validationCode":"// Purge zero-byte files before running webpack\nconst fs = require('fs');\nfor (const f of walk(cacheLocation)) if (fs.statSync(f).size === 0) fs.unlinkSync(f);","typeGuard":null,"tryCatchPattern":"compiler.hooks.failed.tap('EmptyCacheGuard', (err) => {\n  if (/^Empty file/.test(err.message)) {\n    require('fs').rmSync(cacheLocation, { recursive: true, force: true });\n  }\n});","preventionTips":["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)."],"tags":["serialization","cache","corruption","fs","persistence"],"analyzedSha":"318421ea8ac81371f5171236a6efb63675576528","analyzedAt":"2026-08-03T19:39:56.731Z","schemaVersion":2}