Skip to content

Regression: v5.104 -> 5.105: Webpack no longer able to bundle CJS deps when output.library.type = "module" #20436

@dfoley112

Description

@dfoley112

Bug Description

No issues in v5.104.

In v5.105, bundling to library type = "module" , when some of the projects dependencies are CJS (e.g. exceljs), will create runtime errors like:

TypeError: The "superCtor.prototype" property must be of type object. Received undefined
at inherits (node:util:227:11)
at Object.call (file:///C:/Users/redacted/Ui/release/app/dist/main/webpack:/node_modules/readable-stream/lib/_stream_readable.js:76:1)
at webpack_require (file:///C:/Users/redacted/Ui/release/app/dist/main/webpack:/webpack/bootstrap:19:32)
at Object.call (file:///C:/Users/redacted/Ui/release/app/dist/main/webpack:/node_modules/readable-stream/readable.js:7:30)
at webpack_require (file:///C:/Users/redacted/Ui/release/app/dist/main/webpack:/webpack/bootstrap:19:32)
at Object.call (file:///C:/Users/redacted/Ui/release/app/dist/main/webpack:/node_modules/exceljs/lib/xlsx/xlsx.js:3:23)
at webpack_require (file:///C:/Users/redacted/Ui/release/app/dist/main/webpack:/webpack/bootstrap:19:32)
at Object.call (file:///C:/Users/redacted/Ui/release/app/dist/main/webpack:/node_modules/exceljs/lib/doc/workbook.js:5:14)
at webpack_require (file:///C:/Users/redacted/Ui/release/app/dist/main/webpack:/webpack/bootstrap:19:32)
at Object.25046 (file:///C:/Users/redacted/Ui/release/app/dist/main/webpack:/node_modules/exceljs/lib/exceljs.nodejs.js:2:13)

This is not peculiar to one or two CJS dependencies. Adding ExcelJS to webpack externals will just move the error onto the next CJS dep: "ws", "jws"... etc.

Link to Minimal Reproduction and step to reproduce

relevant config:

``
import CopyWebpackPlugin from 'copy-webpack-plugin';
import path from 'path';
// eslint-disable-next-line import/no-named-as-default
import webpack from 'webpack';
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
import { merge } from 'webpack-merge';
import baseConfig from './webpack.config.base.ts';
import webpackPaths from './webpack.paths.ts';

const configuration: webpack.Configuration = {
devtool: 'source-map',

mode: 'production',

target: 'electron40-main',

entry: path.join(webpackPaths.srcMainPath, 'main.ts'),

experiments: {
outputModule: true,
},

resolve: {
extensions: ['.js', '.jsx', '.json', '.ts', '.tsx'],
modules: [webpackPaths.srcPath, 'node_modules'],

// webpack is looking for .js files because ESM modules have
// stricter import rules and we don't use TSConfigPathsPlugin here
extensionAlias: {
  '.js': ['.ts', '.js'],
},

},

output: {
path: webpackPaths.distMainPath,
filename: 'main.js',
library: {
type: 'module',
},
clean: {
keep: /preload.js.*/,
},
}
};

export default merge(baseConfig, configuration);

``

Expected Behavior

Webpack should continue to perform whatever magic it was doing in 5.104 to bundle CJS deps into an ESM output

Actual Behavior

Bundling completes successfully, but app crashes on launch with error messages (like above) that indicate webpack doesn't wrap CJS libraries as successfully as it did in 5.104

Environment

System:
    OS: Windows 11 10.0.26200
    CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
    Memory: 13.31 GB / 31.69 GB
  Binaries:
    Node: 24.1.0 - C:\Program Files\nodejs\node.EXE
    npm: 11.6.2 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Chromium (140.0.3485.54)
    Internet Explorer: 11.0.26100.7309
  Packages:
    add-asset-html-webpack-plugin: ^6.0.0 => 6.0.0 
    copy-webpack-plugin: ^11.0.0 => 11.0.0 
    css-loader: ^6.7.3 => 6.7.3 
    css-minimizer-webpack-plugin: ^7.0.2 => 7.0.2 
    file-loader: ^6.2.0 => 6.2.0 
    html-webpack-plugin: ^5.6.3 => 5.6.3 
    postcss-loader: ^8.1.1 => 8.1.1 
    react-compiler-webpack: ^1.0.0 => 1.0.0 
    style-loader: ^4.0.0 => 4.0.0 
    ts-loader: ^9.5.2 => 9.5.2 
    tsconfig-paths-webpack-plugin: ^4.2.0 => 4.2.0 
    webpack: 5.105 => 5.105.1 
    webpack-bundle-analyzer: ^5.0.1 => 5.0.1 
    webpack-cli: ^6.0.1 => 6.0.1 
    webpack-dev-server: ^5.2.2 => 5.2.2 
    webpack-merge: ^6.0.1 => 6.0.1

Is this a regression?

Yes (please specify version below)

Last Working Version

v5.104

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions