Skip to content

Commit 421c5f8

Browse files
committed
fix: always use CommonJS for the preload injected code
1 parent 3f6d729 commit 421c5f8

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

packages/utils/test-utils/src/template-tests.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,12 @@ export function testForgeTemplate({
164164
preloadPath,
165165
[
166166
'\n',
167-
moduleFormat === 'es'
168-
? `import { ipcRenderer } from 'electron';`
169-
: `const { ipcRenderer } = require('electron');`,
167+
168+
// Renderer processes are sandboxed by default and therefore can't
169+
// run ESM preloads per [the docs](https://github.com/electron/electron/blob/61e815c28ab46eb594b7e4cb2b3256bece81ad2f/docs/tutorial/esm.md?plain=1#L144-L148),
170+
// so we always use CommonJS for the injected preload code
171+
// regardless of the `moduleFormat` option.
172+
`const { ipcRenderer } = require('electron');`,
170173

171174
// If the preload file loads correctly, it will send this message to
172175
// the main process, which will in turn log it. Once the app exits

0 commit comments

Comments
 (0)