Bug report
What is the current behavior?
After upgrading to webpack 5.108.0 (from 5.107.2), production builds crash at runtime with:
Uncaught TypeError: Cannot read properties of undefined (reading 'Y')
at Module.ieVersion (index.js:6:304314)
The error occurs when accessing a property on a namespace re-export object that is undefined at runtime. The pattern in question:
// util/env.js
export var ieVersion = typeof document !== 'undefined' ? document.documentMode : undefined;
export default { ieVersion };
// util/index.js
import * as _env from './env';
export var env = _env; // <-- `env` is undefined at runtime in 5.108.0
// table/index.js (consumer)
import { env } from '../util';
var ieVersion = env.ieVersion; // TypeError: Cannot read properties of undefined
'Y' in the error is the mangled name of ieVersion.
What is the expected behavior?
The namespace object (env) should be a valid module namespace object at runtime, as it was in 5.107.2 and all prior 5.x versions.
Steps to reproduce
- Create a library with a barrel
util/index.js that does import * as _env from './env'; export var env = _env;
- The library's
package.json declares "sideEffects": ["*.css"]
- A consumer module accesses
env.someProperty at the top level (module initialization)
- Build with webpack 5.108.0 in production mode (
mode: 'production')
- The bundle crashes at runtime because
env is undefined
Setting optimization.concatenateModules: false resolves the issue.
Affected package
The reproduction uses @alifd/next@1.27.x (Alibaba Fusion Design), but the bug is in webpack's module concatenation logic and can affect any library using this pattern.
Root cause (likely)
The 5.108.0 release includes:
- "Skipped pure single-star passthrough modules during
export * re-exports"
- "Deferred building unused re-export targets in side-effect-free barrel modules"
- "Fixed merging logic for inner module top-level declarations inside concatenated modules"
One or more of these optimizations incorrectly treats the import * as X; export var y = X pattern as eliminable when the barrel module is marked side-effect-free, causing the namespace binding to be dropped from the concatenated output.
Workaround
optimization: {
concatenateModules: false,
}
Other relevant information:
- webpack version: 5.108.0 (works in 5.107.2)
- Node.js version: 14.19.3 / 22.x (reproducible on both)
- Operating System: Linux (CI) / macOS
- Additional tools: TerserPlugin (standard, not esbuild)
Bug report
What is the current behavior?
After upgrading to webpack 5.108.0 (from 5.107.2), production builds crash at runtime with:
The error occurs when accessing a property on a namespace re-export object that is
undefinedat runtime. The pattern in question:'Y'in the error is the mangled name ofieVersion.What is the expected behavior?
The namespace object (
env) should be a valid module namespace object at runtime, as it was in 5.107.2 and all prior 5.x versions.Steps to reproduce
util/index.jsthat doesimport * as _env from './env'; export var env = _env;package.jsondeclares"sideEffects": ["*.css"]env.somePropertyat the top level (module initialization)mode: 'production')envisundefinedSetting
optimization.concatenateModules: falseresolves the issue.Affected package
The reproduction uses
@alifd/next@1.27.x(Alibaba Fusion Design), but the bug is in webpack's module concatenation logic and can affect any library using this pattern.Root cause (likely)
The 5.108.0 release includes:
export *re-exports"One or more of these optimizations incorrectly treats the
import * as X; export var y = Xpattern as eliminable when the barrel module is marked side-effect-free, causing the namespace binding to be dropped from the concatenated output.Workaround
Other relevant information: