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
Try doing this:
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.