question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to load preload script: 'renderer.prod.js'

See original GitHub issue

I 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:

  1. what’s its effect and why we need renderer.prod.js in production build, even though everything works right without it?
  2. How can I require(‘fs’) properly in harmony with preload.renderer.js. I do not want to modify the original main.dev.ts.

Error screenshot image

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:closed
  • Created 3 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

0reactions
sanzhardanybayevcommented, Feb 4, 2021

@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:

 const mainWindow = new BrowserWindow({
    show: false,
    width: 1024,
    height: 728,
    icon: getAssetPath('logo.png'),
    webPreferences: {
      nodeIntegration: true,
      enableRemoteModule: true,
    },
  });
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found