webpack/webpack · error · Error

Section table does not match file size

Error message

Section table does not match file size

What it means

After walking every section, parsePointerNames asserts the running offset equals the buffer length exactly; any mismatch throws `Section table does not match file size` (lib/serialization/FileMiddleware.js:872-874). The walk either overshot (table over-counted) or undershot (trailing bytes the table does not account for).

Source

Thrown at lib/serialization/FileMiddleware.js:873

	}
	/** @type {string[]} */
	const names = [];
	for (let i = 0; i < sectionCount; i++) {
		const length = buf.readInt32LE(8 + i * 4);
		if (length < 0) {
			// pointer section: u64 size + utf-8 file name
			const end = offset - length;
			if (end > buf.length) {
				throw new Error("Truncated pointer section");
			}
			names.push(buf.toString("utf8", offset + 8, end));
			offset = end;
		} else {
			offset += length;
		}
	}
	if (offset !== buf.length) {
		throw new Error("Section table does not match file size");
	}
	return names;
};

/**
 * Reads the pointer names of a compressed file by decompressing it fully
 * (compressed content cannot be read by byte range).
 * @param {IntermediateFileSystem} fs a file system
 * @param {string} file absolute path of the serialized file
 * @returns {Promise<string[]>} referenced file names (without extension)
 */
const getReferencedFilenamesCompressed = (fs, file) =>
	new Promise((resolve, reject) => {
		fs.readFile(file, (err, rawContent) => {
			if (err) return reject(err);
			/**
			 * Parses the decompressed content.
			 * @param {Error | null} err error

View on GitHub (pinned to 318421ea8a)

Solutions

  1. Delete the cache file and regenerate.
  2. Ensure cache writes are atomic (write-tmp-then-rename) — webpack does this; bypassing it (external copy) can leave trailing bytes.
  3. Make sure nothing appends to cache files.
  4. Confirm a single webpack version owns the cache.

Example fix

// before: trailing bytes after section table -> offset != buf.length
// after
//   rm -rf node_modules/.cache/webpack && yarn webpack
Defensive patterns

Strategy: fallback

Try / catch

compiler.hooks.failed.tap('CacheCorruptionGuard', (err) => {
  if (/Section table does not match file size/.test(err.message)) {
    require('fs').rmSync(cacheLocation, { recursive: true, force: true });
  }
});

Prevention

When it happens

Trigger: Section sizes in the header sum to a length that disagrees with the actual file length — e.g. trailing garbage appended to a cache file, or a section size corrupted to under-count.

Common situations: Append-style writes that left stale bytes at the end; partial overwrite that shrank a section without updating the header; tools that `>>` appended to the cache file; cache file reused across incompatible formats.

Related errors


AI-assisted analysis of webpack/webpack@318421ea8a (2026-08-03). Data as JSON: /data/errors/ba9d3a35736c22fa.json. Report an issue: GitHub.