You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
"ReferenceError: process is not defined" when using ESM mode and contextIsolation is not enabled #46142
34-x-yESMbug 🪲has-repro-gistIssue can be reproduced with code at https://gist.github.com/platform/allstatus/confirmedA maintainer reproduced the bug or agreed with the feature
The renderer and the preload script only have access to contextIsolation (such as process) with nodeIntegration: true.
However, when commonjs mode, the process can be accessed even without nodeIntegration: true,This is an ESM-related issue. In theory, nodeIntegration: true should only affect scripts in the web page.
Sorry for the confusion during the night! Thanks for correcting me.
I can confirm that process is defined in the preload script with CommonJS and contextIsolation disabled (testcase gist) and that it is not defined with ESM and contextIsolation disabled (testcase gist).
Again, sorry for the confusion! I spoke too fast there.
I'll leave this for another team member to review who is more familiar with how sandbox, contextIsolation and nodeIntegration interact.
34-x-yESMbug 🪲has-repro-gistIssue can be reproduced with code at https://gist.github.com/platform/allstatus/confirmedA maintainer reproduced the bug or agreed with the feature
Activity
nikwen commentedon Mar 20, 2025
Does
nodeIntegration: truesolve the issue?haohetao commentedon Mar 20, 2025
Yes,when I add nodeIntegration: true the problem disappears
nikwen commentedon Mar 20, 2025
The renderer and the preload script only have access to Node.js modules (such asprocess) withnodeIntegration: true.That said, for security reasons, it is recommended to
sandbox: true, contextIsolation: true, nodeIntegration: falseSee:
Since this is working as expected, I'll close this issue.haohetao commentedon Mar 20, 2025
@nikwen
However, when commonjs mode, the
processcan be accessed even without nodeIntegration: true,This is an ESM-related issue. In theory, nodeIntegration: true should only affect scripts in the web page.nikwen commentedon Mar 20, 2025
Reopening in case I misunderstood something myself.
nikwen commentedon Mar 20, 2025
Sorry for the confusion during the night! Thanks for correcting me.
I can confirm that
processis defined in the preload script with CommonJS andcontextIsolationdisabled (testcase gist) and that it is not defined with ESM andcontextIsolationdisabled (testcase gist).Again, sorry for the confusion! I spoke too fast there.
I'll leave this for another team member to review who is more familiar with how
sandbox,contextIsolationandnodeIntegrationinteract.clavin commentedon Apr 3, 2025
This indeed appears to be a bug. It's a shot in the dark, but I suspect we might be deleting these globals too early.
I also want to emphasize that we recommend using the sandbox and context isolation features of Electron, as @nikwen said above.