Skip to content

5.106.0 regression: ReferenceError: __WEBPACK_DEFAULT_EXPORT__ is not defined in SSR/eval contexts #20793

@ihabadham

Description

@ihabadham

Bug report

What is the current behavior?

After upgrading from webpack 5.105.4 to 5.106.0, server-side rendering via ExecJS produces:

ReferenceError: __WEBPACK_DEFAULT_EXPORT__ is not defined

when evaluating a server bundle that includes modules with anonymous default exports (arrow functions).

The webpack compilation itself succeeds — the error occurs at runtime when the compiled bundle is evaluated via eval() (ExecJS in Ruby, used for SSR).

What is the expected behavior?

The compiled bundle should evaluate without errors, as it did in 5.105.4.

Steps to reproduce

  1. A module with an anonymous default export:
// scriptSanitizedVal.js
export default (val) => {
    const re = /<\/\W*script/gi;
    return val.replace(re, '(/script');
};
  1. Webpack config with server bundle output:
{
  output: {
    libraryTarget: 'commonjs2'
  }
}
  1. Compile with webpack 5.106.0
  2. Evaluate the server bundle via eval() or ExecJS (Ruby SSR)
  3. ReferenceError: __WEBPACK_DEFAULT_EXPORT__ is not defined

Suspected cause

PR #20773 ("fix: set .name to 'default' for anonymous default exports per ES spec") adds Reflect.defineProperty(__WEBPACK_DEFAULT_EXPORT__, "name", ...) calls after anonymous arrow function exports. In eval()-based execution contexts (like ExecJS for Ruby SSR), the __WEBPACK_DEFAULT_EXPORT__ variable reference in the Reflect.defineProperty call is not properly resolved.

This is similar to past regressions #19394 and #10542 where code generation assumed a standard module loader context.

Evidence

  • 5.105.4 passes: CI run on main (2026-04-08 10:48 UTC, webpack 5.105.4) — all examples pass
  • 5.106.0 fails: CI run on main (2026-04-08 16:44 UTC, webpack 5.106.0) — SSR examples fail
  • Same codebase, same commit, only difference is webpack version resolved by ^5.x range
  • Downgrading to 5.105.4 in the generated example app fixes the issue

Environment

  • webpack: 5.106.0
  • Node.js: 22.x
  • ExecJS runtime: mini_racer (V8-based, Ruby SSR)
  • OS: Ubuntu (GitHub Actions runner)
  • Shakapacker: 9.7.0

Workaround

Pin webpack to <5.106.0 or 5.105.4 in package.json.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions