Unable to load preload script: 'renderer.prod.js'
See original GitHub issueI have the problem Unable to load preload script: /Users/waltermitty/Code/cvte/electron-easi-camera/app/dist/renderer.prod.js. If I add nodeIntegration: true,, My project can work. But the console error is still. My questions are:
- what’s its effect and why we need
renderer.prod.jsin production build, even though everything works right without it? - How can I require(‘fs’) properly in harmony with
preload.renderer.js. I do not want to modify the originalmain.dev.ts.
Error screenshot

If you need any further info, plz let me know and I will append as soon as possible.
Update
I found the reason caused the error: I require node native fs module in my react component. Because I want to implement saving file function. When I remove the require('fs'), error gone.Here is my code snippet:
const fs = require('electron').remote.require('fs');
fs.writeFile(`${url}/${name}`, buf, (err: Error) => {
if (err) {
logger.error(err);
} else {
logger.log('save file successfully!');
}
});
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (1 by maintainers)
Top Results From Across the Web
electron-builder with browserWindow and preload.js. Unable ...
Unable to load preload script, but actually something was wrong with the initialize.js. in my file, has an error that remote.
Read more >Unable to load preload script #2931 - electron/forge - GitHub
0.0 on MacOS 12.5 by trying to use a Web Worker. Specifically by using worker-loader and adding this rule to the webpack.renderer.config.js.
Read more >Unable to require path and fs modules in preload script - Reddit
I have been trying to resolve this issue for the last 3 hours and am unable to make any progress. The preload script...
Read more >Using NodeJS APIs in Electron with React - Ryosuke
When we call that method, the IPC Renderer inside the preload script runs (or invoke() ) the function we put in the main...
Read more >Electron Preload Script - Quasar Framework
js code and bridge it to the renderer thread through an Electron Preload script located at /src-electron/electron-preload.[js|ts] . Use contextBridge (from the ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

this fixed this issue for me! https://github.com/electron-react-boilerplate/electron-react-boilerplate/pull/2503/commits/1d97ac110321288b0068c55ca458e3563b751551
@kingpalethe By default, electron doesn’t let you to access remote module. In order to get access to it, you need to enable it by setting enableRemoteModule to true in webPreferences property when instantiating BrowserWindow . Here’s an official solution: