From 1b888437ad7222bb231dc2d4d5fee01ecce1dbe4 Mon Sep 17 00:00:00 2001 From: Erick Zhao Date: Wed, 8 Apr 2026 14:25:17 -0700 Subject: [PATCH 1/2] fix(plugin-webpack): ESM-compatible imports --- packages/plugin/webpack/src/WebpackConfig.ts | 8 +++++--- packages/plugin/webpack/src/WebpackPlugin.ts | 8 ++++---- tools/test-dist.ts | 15 +++++++++++++++ 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/packages/plugin/webpack/src/WebpackConfig.ts b/packages/plugin/webpack/src/WebpackConfig.ts index 3235d8c08e..37ef86dc08 100644 --- a/packages/plugin/webpack/src/WebpackConfig.ts +++ b/packages/plugin/webpack/src/WebpackConfig.ts @@ -2,8 +2,10 @@ import path from 'node:path'; import debug from 'debug'; import HtmlWebpackPlugin from 'html-webpack-plugin'; -import * as webpack from 'webpack'; -import { DefinePlugin, ExternalsPlugin, WebpackPluginInstance } from 'webpack'; +import type * as webpack from 'webpack'; +import webpackPkg from 'webpack'; + +const { DefinePlugin, ExternalsPlugin } = webpackPkg; import { merge as webpackMerge } from 'webpack-merge'; import { @@ -366,7 +368,7 @@ export default class WebpackConfigGenerator { template: entryPoint.html, filename: `${entryPoint.name}/index.html`, chunks: [entryPoint.name].concat(entryPoint.additionalChunks || []), - }) as WebpackPluginInstance, + }) as webpack.WebpackPluginInstance, ); } } diff --git a/packages/plugin/webpack/src/WebpackPlugin.ts b/packages/plugin/webpack/src/WebpackPlugin.ts index b207845317..cc50c7f522 100644 --- a/packages/plugin/webpack/src/WebpackPlugin.ts +++ b/packages/plugin/webpack/src/WebpackPlugin.ts @@ -20,7 +20,7 @@ import debug from 'debug'; import glob from 'fast-glob'; import fs from 'fs-extra'; import { PRESET_TIMER } from 'listr2'; -import * as webpack from 'webpack'; +import webpack from 'webpack'; import WebpackDevServer from 'webpack-dev-server'; import { merge } from 'webpack-merge'; @@ -145,7 +145,7 @@ export default class WebpackPlugin extends PluginBase { rendererOptions: WebpackPluginRendererConfig | null, ): Promise => new Promise((resolve, reject) => { - webpack.webpack(options).run(async (err, stats) => { + webpack(options).run(async (err, stats) => { if (rendererOptions && rendererOptions.jsonStats) { for (const [index, entryStats] of (stats?.stats ?? []).entries()) { const name = rendererOptions.entryPoints[index].name; @@ -639,7 +639,7 @@ the generated files). Instead, it is ${JSON.stringify(pj.main)}`); const mainConfig = await this.configGenerator.getMainConfig(); await new Promise((resolve, reject) => { - const compiler = webpack.webpack(mainConfig); + const compiler = webpack(mainConfig); const [onceResolve, onceReject] = once(resolve, reject); const cb: WebpackWatchHandler = async (err, stats) => { if (tab && stats) { @@ -741,7 +741,7 @@ the generated files). Instead, it is ${JSON.stringify(pj.main)}`); entryConfig.stats = 'none'; } - const compiler = webpack.webpack(configs); + const compiler = webpack(configs); const promises = preloadPlugins.map((preloadPlugin) => { return new Promise((resolve, reject) => { diff --git a/tools/test-dist.ts b/tools/test-dist.ts index eb80edaaa2..6e6c76cf2c 100644 --- a/tools/test-dist.ts +++ b/tools/test-dist.ts @@ -6,6 +6,10 @@ import fs from 'fs-extra'; const BASE_DIR = path.resolve(import.meta.dirname, '..'); const PACKAGES_DIR = path.resolve(BASE_DIR, 'packages'); +// Packages whose entry points have top-level side effects (CLI scripts) +// that cannot be safely imported in a test context. +const SKIP_IMPORT = new Set(['create-electron-app']); + (async () => { const dirsToCheck: string[] = []; @@ -46,6 +50,17 @@ const PACKAGES_DIR = path.resolve(BASE_DIR, 'packages'); chalk.red(`Main entry not found (${main})`), ); bad = true; + } else if (!SKIP_IMPORT.has(pj.name)) { + try { + await import(path.resolve(dir, main)); + } catch (err: unknown) { + const message = err instanceof Error ? err.message : String(err); + console.error( + `${chalk.cyan(`[${pj.name}]`)}:`, + chalk.red(`Failed to import main entry (${main}): ${message}`), + ); + bad = true; + } } if (!typings || !(await fs.pathExists(path.resolve(dir, typings)))) { console.error( From 9f0e1a0ae2f2b024ba891c0d57b51c0d06fd966a Mon Sep 17 00:00:00 2001 From: Erick Zhao Date: Wed, 8 Apr 2026 15:38:09 -0700 Subject: [PATCH 2/2] windows interop --- tools/test-dist.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/test-dist.ts b/tools/test-dist.ts index 6e6c76cf2c..93ae13c008 100644 --- a/tools/test-dist.ts +++ b/tools/test-dist.ts @@ -1,4 +1,5 @@ import * as path from 'node:path'; +import { pathToFileURL } from 'node:url'; import chalk from 'chalk'; import fs from 'fs-extra'; @@ -52,7 +53,7 @@ const SKIP_IMPORT = new Set(['create-electron-app']); bad = true; } else if (!SKIP_IMPORT.has(pj.name)) { try { - await import(path.resolve(dir, main)); + await import(pathToFileURL(path.resolve(dir, main)).href); } catch (err: unknown) { const message = err instanceof Error ? err.message : String(err); console.error(