Skip to content

Commit

Permalink
fix: convert path to file url before importing
Browse files Browse the repository at this point in the history
  • Loading branch information
MarshallOfSound committed Mar 9, 2023
1 parent acf384c commit 6f20236
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lib/browser/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,9 @@ if (packagePath) {
// Finally load app's main.js and transfer control to C++.
if ((packageJson.type === 'module' && !mainStartupScript.endsWith('.cjs')) || mainStartupScript.endsWith('.mjs')) {
const { loadESM } = __non_webpack_require__('internal/process/esm_loader');
const main = path.join(packagePath, mainStartupScript);
const main = require('url').pathToFileURL(path.join(packagePath, mainStartupScript));
loadESM((esmLoader: any) => {
return esmLoader.import(main, undefined, Object.create(null)).then(() => {
return esmLoader.import(main.toString(), undefined, Object.create(null)).then(() => {
appCodeLoaded!();
}).catch((err: Error) => {
appCodeLoaded!();
Expand Down
15 changes: 9 additions & 6 deletions lib/renderer/init.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as path from 'path';
import { pathToFileURL } from 'url';
import { IPC_MESSAGES } from '@electron/internal/common/ipc-messages';

import type * as ipcRendererInternalModule from '@electron/internal/renderer/ipc-renderer-internal';
Expand Down Expand Up @@ -131,12 +132,14 @@ if (preloadPaths.length) {

loadESM((esmLoader: any) => {
// Load the preload scripts.
return Promise.all(preloadPaths.map(preloadScript => esmLoader.import(preloadScript, undefined, Object.create(null)).catch((err: Error) => {
console.error(`Unable to load preload script: ${preloadScript}`);
console.error(err);

ipcRendererInternal.send(IPC_MESSAGES.BROWSER_PRELOAD_ERROR, preloadScript, err);
})));
return Promise.all(preloadPaths.map(preloadScript => {
esmLoader.import(pathToFileURL(preloadScript).toString(), undefined, Object.create(null)).catch((err: Error) => {
console.error(`Unable to load preload script: ${preloadScript}`);
console.error(err);

ipcRendererInternal.send(IPC_MESSAGES.BROWSER_PRELOAD_ERROR, preloadScript, err);
});
}));
}).then(() => appCodeLoaded!());
} else {
appCodeLoaded!();
Expand Down

0 comments on commit 6f20236

Please sign in to comment.