{"id":"e7818b22c833669c","repo":"webpack/webpack","slug":"data-was-written-with-v8-serialization-format-vers","errorCode":null,"errorMessage":"Data was written with V8 serialization format version ${payload[1]}, but this Node.js (${process.version}) only reads up to version ${V8_FORMAT_VERSION}","messagePattern":"Data was written with V8 serialization format version (.+?), but this Node\\.js \\((.+?)\\) only reads up to version (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/serialization/BinaryMiddleware.js","lineNumber":226,"sourceCode":"\t\treturn this.read(I32_SIZE).readUInt32LE(0);\n\t}\n}\n\n/**\n * Reads a section of values written by V8's value serializer.\n * @param {ReadState} state read state\n * @returns {DeserializedType} values of the section\n */\nconst readValuesSection = (state) => {\n\tconst payloadSize = state.readU32();\n\tconst bufferCount = state.readU32();\n\t/** @type {number[]} */\n\tconst bufferInfo = [];\n\tfor (let i = 0; i < bufferCount * 2; i++) bufferInfo.push(state.readU32());\n\tconst payload = state.read(payloadSize);\n\t// a V8 payload opens with 0xff and its format version, which only ever grows\n\tif (payload[0] === 0xff && payload[1] > V8_FORMAT_VERSION) {\n\t\tthrow new Error(\n\t\t\t`Data was written with V8 serialization format version ${payload[1]}, but this Node.js (${process.version}) only reads up to version ${V8_FORMAT_VERSION}`\n\t\t);\n\t}\n\tconst values = /** @type {DeserializedType} */ (v8Deserialize(payload));\n\tfor (let i = 0; i < bufferCount; i++) {\n\t\tvalues[bufferInfo[i * 2]] = state.retainedBuffer(\n\t\t\tstate.read(bufferInfo[i * 2 + 1])\n\t\t);\n\t}\n\treturn values;\n};\n\n/**\n * Reads the content items of a lazy section.\n * @param {ReadState} state read state\n * @returns {SerializedType} content of the lazy value\n */\nconst readLazySection = (state) => {","sourceCodeStart":208,"sourceCodeEnd":244,"githubUrl":"https://github.com/webpack/webpack/blob/318421ea8ac81371f5171236a6efb63675576528/lib/serialization/BinaryMiddleware.js#L208-L244","documentation":"readValuesSection checks the V8 serializer header embedded in a values section and rejects payloads whose format-version byte exceeds what the running Node.js's V8 can decode (lib/serialization/BinaryMiddleware.js:225). V8's wire format only grows, so a higher version byte means the cache was written by a newer Node than the one reading it.","triggerScenarios":"A cache written under Node 22 (newer V8 format) is read under Node 18 (older V8). The check `payload[0] === 0xff && payload[1] > V8_FORMAT_VERSION` fires before v8.deserialize is attempted.","commonSituations":"Downgrading Node locally; CI matrix mixing Node versions while sharing a cache volume; teammates on different Node majors; switching between Node and Bun (which ships its own V8) sharing a cache.","solutions":["Use the same Node major version that wrote the cache, or upgrade Node.","Delete the cache directory once and let it rebuild under the current Node.","Scope `cache.cacheLocation` per Node version (e.g. include `process.versions.node` in the path).","Set `cache.version` to a string that encodes the Node major so webpack invalidates automatically."],"exampleFix":"// before: shared cache between Node 18 and Node 22\n// after: scope cache per node major\nconst path = require('path');\nconfig.cache = {\n  type: 'filesystem',\n  cacheLocation: path.join(__dirname, '.cache', process.versions.node)\n};","handlingStrategy":"fallback","validationCode":"// Scope or invalidate the cache when the Node major changes\nconst cacheDir = path.join(__dirname, '.cache', `node-${process.versions.node.split('.')[0]}`);\nconfig.cache = { type: 'filesystem', cacheLocation: cacheDir };","typeGuard":null,"tryCatchPattern":"compiler.hooks.failed.tap('V8VersionGuard', (err) => {\n  if (/V8 serialization format version/.test(err.message)) {\n    require('fs').rmSync(cacheLocation, { recursive: true, force: true });\n    console.error('Cache was written by a newer Node; purged. Rebuild.');\n  }\n});","preventionTips":["Use the same Node major across writers and readers of a cache.","Encode the Node major in `cacheLocation` or `cache.version`.","Do not share caches between Node and Bun."],"tags":["serialization","cache","versioning","node","v8","persistence"],"analyzedSha":"318421ea8ac81371f5171236a6efb63675576528","analyzedAt":"2026-08-03T19:39:56.731Z","schemaVersion":2}