parseBundle finds no modules in webpack 5 ESM output (`output.module`), so parsed and gzip sizes are missing

Ouverte
#757 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

@goranai y travaille déjà.

Depuis le 23/11/2026.

  • #758 par @goranai — ouverte

Évaluation

Difficulté
3/5
Temps estimé
1-2 jours
Accessibilité débutants
38/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
javascript, webpack
Domaine
build-system

Piste de recherche

Start in src/parseUtils.js at parseBundle, following how it walks the AST for IIFE-wrapped module maps. Two gaps to cover: an ExportNamedDeclaration case for export const __webpack_esm_modules__ (and older export const modules), and top-level var __webpack_modules__ = ({...}) entry chunks where no IIFE wraps the map, so the runtime IIFE is not mistaken for it. Reproduce with the small ESM fixture from the report and check getViewerData shows parsed and gzip sizes for main.mjs and 480.chunk.mjs. Note the reporter says a fix and tests are already in an incoming pull request, so coordinate before starting.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

Bug Description

When a webpack 5 build uses experiments.outputModule with output.module: true, the analyzer does not crash anymore (#684, fixed by #685), but every module of the ESM build shows no parsed size and no gzip size. Only the stat size is shown.

parseBundle in src/parseUtils.js misses the module map in two places of the ESM chunk format:

  1. Async chunks export the map: export const __webpack_esm_modules__ = { ... }; (older webpack 5 releases: export const modules = { ... }). There is no ExportNamedDeclaration case, so modules is {}.
  2. The entry chunk has no wrapping IIFE. The map is a top-level var __webpack_modules__ = ({ ... }). Only IIFE bodies are inspected, so the small runtime IIFE (() => { var installedChunks = { 792: 0 }; ... })() is taken as the module map (0 looks like a deduplicated module id). The result is modules = { "792": "0" } and the real modules are not found.
Steps to Reproduce

Tested on main at a90b30c6dedae8343acaed2b0f7857c95ec89bd1 with webpack 5.105.2, Node 24.

src/index.js: import { a } from "./a.js"; console.log(a); import("./lazy.js").then(m => console.log(m.b));
src/a.js:     export const a = "hello a";
src/lazy.js:  import { c } from "./c.js"; export const b = "lazy b" + c;
src/c.js:     export const c = "ccc";

webpack config: mode: "production", target: "node", experiments: { outputModule: true }, output: { module: true, chunkFormat: "module", filename: "[name].mjs", chunkFilename: "[name].chunk.mjs" }, optimization: { concatenateModules: false, minimize: false }. Then call getViewerData(stats, outputPath).

Actual behavior (path, statSize, parsedSize)
main.mjs      [["./src/index.js",93,null],["./src/a.js",28,null]]
480.chunk.mjs [["./src/lazy.js",57,null],["./src/c.js",24,null]]

parseBundle keys: main.mjs gives ['792'] (wrong), 480.chunk.mjs gives [].

Expected behavior

The same project built without output.module gives a.js 242, lazy.js 368, c.js 238 (index.js stays null there, it is the concatenated entry module, documented). The ESM build should give the same:

main.mjs      [["./src/index.js",93,null],["./src/a.js",28,242]]
480.chunk.mjs [["./src/lazy.js",57,368],["./src/c.js",24,238]]
Real usage

output.module with this analyzer is used in real projects: #684 (user builds index.mjs), and the @wordpress/scripts webpack config in WordPress/gutenberg enables experiments.outputModule and output.module for script modules and BundleAnalyzerPlugin behind WP_BUNDLE_ANALYZER.

A fix and tests are in the pull request I am sending with this issue.

Validated with Claude Opus 5.5.

Langage dominant
JavaScript
Étoiles
12.7k
Forks
521
Merge moyen
2 j 9 h
PR mergées (30 j)
7

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de webpack/webpack-bundle-analyzer

Toutes les issues de webpack/webpack-bundle-analyzer

Issues similaires

Plus d'issues JavaScript

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.