New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: Unable to load preload script due enable sandbox by default #36437
Comments
Hey @oalfroukh, thanks for reporting this issue! This is happening because your preload script is trying to use node in the renderer process, which Electron no longer allows by default. It's not technically a bug; this is by design. Like you mentioned above, you can get around this in the short-term by explicitly specifying Since this isn't technically a bug, I'm going to close this issue, but if you'd like to discuss further, let me know and I can reopen it. Thanks! |
Hi @VerteDinde What if i disabled sandox, enable ContextIsolation to true and want to use require API to import relative module/script? Does it also cause issue in future as you suggested to refactor renderer process to remove Node.js usge. main.js const windowConfig = {
width: winState.width,
height: winState.height,
x: winState.x,
y: winState.y,
show: false,
webPreferences: {
sandbox: false,
contextIsolation: true,
preload: path.join(__dirname, `preload.js`)
}
} preload.js const { contextBridge } = require('electron');
const module = require('./module')
contextBridge.exposeInMainWorld('api', {
module
}) |
Preflight Checklist
Electron Version
21.3.1
What operating system are you using?
Windows
Operating System Version
Windows 10.0.19041
What arch are you using?
x64
Last Known Working Electron version
19.1.6
Expected Behavior
Loading preload script without issues.
Actual Behavior
Unable to load preload script due to
Error: module not found: inversify
Testcase Gist URL
No response
Additional Information
We are using InversifyJS library to inversion of control (IoC) container for TypeScript in both the main and renderer process in our project, it's OK on the
main process
while not on therenderer process
.Electron
v20
has a breaking change feat: sandbox preloads by default #35125 , after enablingsandbox
we got an errorError: module not found: inversify
that will prevent loading thepreload script
, while when disablingsandbox
will be OK, but we would like to apply Electron recommendations for the security on our app.Electron Fiddle project
that doesn't supportts
, Here is a quick app on GitHub to reproduce the issue** Edit: Here is Electron Fiddle project with the same issue when using
jszip
library.The text was updated successfully, but these errors were encountered: