vite-plugin-electron: importing electron in a WebWorker doesn't work

Doing import { ipcRenderer} from 'electron' (or any other renderer electron module) crashes the app with reason: "crashed" and exitCode: 11.

Details

  • I’m trying to migrate from Webpack and the same code works there.
  • nodeIntegrationInWorker is set to true.
  • Exit code 11 usually means Segmentation fault.
  • One thing that is being logged in the Terminal when the app crashes:
    [20890:0831/172750.464535:ERROR:shared_image_manager.cc(267)] SharedImageManager::ProduceOverlay: Trying to Produce a Overlay representation from a non-existent mailbox.
    [20890:0831/172750.464559:ERROR:skia_output_device_buffer_queue.cc(354)] Invalid mailbox.
    [20890:0831/172750.464564:ERROR:shared_image_manager.cc(267)] SharedImageManager::ProduceOverlay: Trying to Produce a Overlay representation from a non-existent mailbox.
    [20890:0831/172750.464569:ERROR:skia_output_device_buffer_queue.cc(354)] Invalid mailbox.
    [20890:0831/172750.464572:ERROR:shared_image_manager.cc(267)] SharedImageManager::ProduceOverlay: Trying to Produce a Overlay representation from a non-existent mailbox.
    [20890:0831/172750.464578:ERROR:skia_output_device_buffer_queue.cc(354)] Invalid mailbox.
    [20890:0831/172750.464580:ERROR:shared_image_manager.cc(267)] SharedImageManager::ProduceOverlay: Trying to Produce a Overlay representation from a non-existent mailbox.
    [20890:0831/172750.464584:ERROR:skia_output_device_buffer_queue.cc(354)] Invalid mailbox.
    [20890:0831/172750.464601:ERROR:shared_image_manager.cc(267)] SharedImageManager::ProduceOverlay: Trying to Produce a Overlay representation from a non-existent mailbox.
    [20890:0831/172750.464606:ERROR:skia_output_device_buffer_queue.cc(354)] Invalid mailbox.
    [20890:0831/172750.464609:ERROR:shared_image_manager.cc(267)] SharedImageManager::ProduceOverlay: Trying to Produce a Overlay representation from a non-existent mailbox.
    [20890:0831/172750.464612:ERROR:skia_output_device_buffer_queue.cc(354)] Invalid mailbox.
    
  • Another thing:
    Error sending from webFrameMain:  Error: Render frame was disposed before WebFrameMain could be accessed
        at n._sendInternal (node:electron/js2c/browser_init:165:629)
        at b._sendInternal (node:electron/js2c/browser_init:161:2573)
        at node:electron/js2c/browser_init:193:729
        at new Promise (<anonymous>)
        at Object.invokeInWebContents (node:electron/js2c/browser_init:193:477)
        at b.executeJavaScript (node:electron/js2c/browser_init:161:3267)
        at process.processTicksAndRejections (node:internal/process/task_queues:96:5)
    

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 23 (22 by maintainers)

Most upvoted comments

type: "module" will be supported in v0.9.3, coming soon. 🚚

Awesome! Thanks for all the work you put into this!

Another idea: You can throw an error if someone tries to access an ipcRenderer property (using a Proxy) and explain the issue. This will be very helpful to other users.

Good idea! I will fix it in next version. 🚚

Done. Here is the repo: https://github.com/astoilkov/electron-vite-worker-issue.

The important part is in renderer/main.ts:

document.body.addEventListener('click', () => {
  new Worker(new URL('./worker.ts', import.meta.url), {
    type: 'module'
  })
})

Clicking on the β€œhello” text will run the code and the BrowserWindow will crash. You can open DevTools before you click the β€œhello” text so you can see DevTools shows a message as well.

@Jazcash πŸ‘‹ This project is just for my personal interest, I have not tested many cases, such as web worder. By the way, Vite behaves very differently during vite serve andvite build, so I run into really tricky issues a lot of the time.

The web worder will be imported by Vite as a separate file during development, and will be correctly loaded by Electron-Renderer as http. During a Vite build, all files will be built into on bundle file, this difference may be the main cause of the BUG 🐞.

Yep, I will do it on Monday.