skip to Main Content

Under the preload/index.ts directory:

I imported {Menu} from "electron"; however, when I printed Menu, it turned out to be undefined.

import { Menu, ipcRenderer } from 'electron';

console.log('imported status: ', Menu, ipcRenderer)  // the Menu: undefined, the ipcRenderer has value

Could you please tell me how it should be imported correctly?

my electron version: "electron": "^31.0.2",

2

Answers


  1. Try doing this:

    import { Menu, ipcRenderer } from 'electron';
    
    setTimeout(() => {
    console.log('imported status: ', Menu, ipcRenderer)
    }, 1000)
    
    Login or Signup to reply.
  2. As stated on the docs of Menu, it is only available on the main process. Thus, you can’t import it on the preload. If you need to interact with the menu, initialize it on main, and use IPC to communicate between your processes.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search