GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — ESM entry chunk hash ignores the hashes of the chunks it imports, so the filesystem cache serves a stale entry chunk · Issue #22803 · webpack/webpack Closed Labels area: cachePersistent and memory caching, serialization (lib/cache, lib/serialization)area: optimizationTree-shaking, splitChunks, concatenation, ids (lib/optimize, lib/ids) DescriptionHave you used AI?Yes. AI-assisted investigation and report; the standalone reproducer below was executed against unmodified npm installations of webpack 5.111.0 and 5.112.0. Which part of webpack is affected?cache (persistent/filesystem cache) Bug DescriptionWith ESM output ( import __webpack_require__ from "./runtime.<hash>.js"; import * as __webpack_chunk_1__ from "./lib.<hash>.js"; The hash of that entry chunk does not depend on the hashes of those chunks. With the filesystem cache the rendered asset is looked up by that unchanged hash, so the previous render is served, and it imports the old file name of the split chunk, which is no longer emitted:
The runtime chunk hash only masks this when the runtime changes too (e.g. when an async chunk changes as well), so in real projects it shows up intermittently, as a cache error that goes away on retry. Link to Minimal Reproduction and steps to reproduceIn an empty directory: npm init -y npm install --save-exact [email protected] # save the script below as repro.cjs node repro.cjs # stale import, exit code 1 node repro.cjs --real-content-hash # RealContentHashPlugin error, exit code 1 The script builds an entry ( Self-contained repro.cjs (creates and removes its own fixture)const assert = require('node:assert/strict'); const fs = require('node:fs/promises'); const os = require('node:os'); const path = require('node:path'); const webpack = require('webpack'); (async () => { const directory = await fs.mkdtemp(path.join(os.tmpdir(), 'webpack-entry-hash-')); async function build() { const compiler = webpack({ mode: 'production', context: directory, entry: { main: './entry.js' }, cache: { type: 'filesystem', cacheDirectory: path.join(directory, '.cache') }, experiments: { outputModule: true }, output: { path: path.join(directory, 'dist'), filename: '[name].[contenthash].js', module: true, clean: true }, optimization: { minimize: false, realContentHash: process.argv[2] === '--real-content-hash', runtimeChunk: 'single', splitChunks: { cacheGroups: { lib: { name: 'lib', chunks: (chunk) => chunk.name === 'main', test: /lib\.js$/, enforce: true } } } } }); await new Promise((resolve, reject) => compiler.run((error, stats) => compiler.close((closeError) => { if (error || closeError) reject(error || closeError); else if (stats.hasErrors()) reject(new Error(stats.toString({ all: false, errors: true }))); else resolve(); }))); const files = await fs.readdir(path.join(directory, 'dist')); const main = files.find((file) => file.startsWith('main.')); const source = await fs.readFile(path.join(directory, 'dist', main), 'utf8'); const imports = [...source.matchAll(/from\s*"\.\/([^"]+)"/g)].map(([, file]) => file); return { files, imports }; } try { await fs.writeFile(path.join(directory, 'entry.js'), 'import { greet } from "./lib.js";\ngreet();\n'); await fs.writeFile(path.join(directory, 'lib.js'), 'export const greet = () => console.log("one");\n'); const first = await build(); await fs.writeFile(path.join(directory, 'lib.js'), 'export const greet = () => console.log("two");\n'); const second = await build(); console.log({ webpack: webpack.version, first, second }); for (const file of second.imports) { assert.ok(second.files.includes(file), `main imports ${file}, which was not emitted`); } } finally { await fs.rm(directory, { recursive: true, force: true }); } })().catch((error) => { console.error(error.message); process.exitCode = 1; }); Expected BehaviorThe second build emits an entry chunk that imports the new Actual BehaviorThe entry chunk keeps its file name and content from the first build and imports Rebuilding with an empty cache directory produces correct output. Environment
Additional Context
updateHashForEntryStartup(hash, chunkGraph, entries, chunk); + for (const [, entrypoint] of entries) { + for (const c of getAllChunks(entrypoint, chunk, runtimeChunk)) { + hash.update(`${c.contentHash.javascript || c.hash || ""}`); + } + } }; With this change the reproducer passes, and a rebuild without source changes keeps every file name. The same handler is used by Activity
MetadataMetadataAssigneesLabelsarea: cachePersistent and memory caching, serialization (lib/cache, lib/serialization)area: optimizationTree-shaking, splitChunks, concatenation, ids (lib/optimize, lib/ids) TypeFieldsPriority None yet ProjectsMilestoneRelationshipsDevelopmentIssue actions |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |