fix: allow importing from electron/utility at runtime (#47989)

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: David Sanders <dsanders11@ucsbalum.com>
This commit is contained in:
trop[bot] 2025-08-07 12:12:42 +02:00 committed by GitHub
commit f6a2c13740
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 6 deletions

View file

@ -93,20 +93,23 @@ makeElectronModule('electron');
makeElectronModule('electron/common'); makeElectronModule('electron/common');
if (process.type === 'browser') { if (process.type === 'browser') {
makeElectronModule('electron/main'); makeElectronModule('electron/main');
} } else if (process.type === 'renderer') {
if (process.type === 'renderer') {
makeElectronModule('electron/renderer'); makeElectronModule('electron/renderer');
} else if (process.type === 'utility') {
makeElectronModule('electron/utility');
} }
const originalResolveFilename = Module._resolveFilename; const originalResolveFilename = Module._resolveFilename;
// 'electron/main', 'electron/renderer' and 'electron/common' are module aliases // 'electron/{common,main,renderer,utility}' are module aliases
// of the 'electron' module for TypeScript purposes, i.e., the types for // of the 'electron' module for TypeScript purposes, i.e., the types for
// 'electron/main' consist of only main process modules, etc. It is intentional // 'electron/main' consist of only main process modules, etc. It is intentional
// that these can be `require()`-ed from both the main process as well as the // that these can be `require()`-ed from both the main process as well as the
// renderer process regardless of the names, they're superficial for TypeScript // renderer process regardless of the names, they're superficial for TypeScript
// only. // only.
const electronModuleNames = new Set(['electron', 'electron/main', 'electron/renderer', 'electron/common']); const electronModuleNames = new Set([
'electron', 'electron/main', 'electron/renderer', 'electron/common', 'electron/utility'
]);
Module._resolveFilename = function (request, parent, isMain, options) { Module._resolveFilename = function (request, parent, isMain, options) {
if (electronModuleNames.has(request)) { if (electronModuleNames.has(request)) {
return 'electron'; return 'electron';

View file

@ -1,8 +1,7 @@
import { fetchWithSession } from '@electron/internal/browser/api/net-fetch'; import { fetchWithSession } from '@electron/internal/browser/api/net-fetch';
import { ClientRequest } from '@electron/internal/common/api/net-client-request'; import { ClientRequest } from '@electron/internal/common/api/net-client-request';
import { IncomingMessage } from 'electron/utility'; import type { ClientRequestConstructorOptions, IncomingMessage } from 'electron/utility';
import type { ClientRequestConstructorOptions } from 'electron/utility';
const { isOnline, resolveHost } = process._linkedBinding('electron_common_net'); const { isOnline, resolveHost } = process._linkedBinding('electron_common_net');