我正在创建一个新的electron应用程序,但遇到了一个之前从未遇到的问题。
我使用了import {ipcRenderer} from 'electron'
并使用了ipcRenderer.send
,但在编译渲染器代码时会显示此错误。
在最新的electron和electron forge中,在任何渲染器代码中导入electron并使用它都会导致错误并终止。
我在electron中使用React,我的上一个项目也使用了React+Electron,但是使用electron模块没有问题。
我能做的所有事情都不起作用,包括降级electron包。
完整的日志:
yarn run v1.22.10
$ electron-forge start
√ Checking your system
√ Locating Application
√ Preparing native dependencies
√ Compiling Main Process Code
√ Launch Dev Servers
√ Compiling Preload Scripts
√ Launching Application
Webpack Output Available: http://localhost:9000
\ Compiling Renderer Code
An unhandled rejection has occurred inside Forge:
[Error: EISDIR: illegal operation on a directory, read] {
errno: -4068,
code: 'EISDIR',
syscall: 'read'
}
Electron Forge was terminated. Location:
{}
error Command failed with exit code 1.
我尝试重新安装所有软件包,但仍然无法工作。 为什么?如何解决? 即使我在webpack.renderer.config.json中添加了
target: 'node'
,窗口最终能够显示,但ipcRender无法发送消息。Uncaught TypeError: Cannot read property 'send' of undefined
at onClick (TitleBar.tsx?3219:11)
at HTMLUnknownElement.callCallback (react-dom.development.js?6ac8:3945)
at Object.invokeGuardedCallbackDev (react-dom.development.js?6ac8:3994)
at invokeGuardedCallback (react-dom.development.js?6ac8:4056)
at invokeGuardedCallbackAndCatchFirstError (react-dom.development.js?6ac8:4070)
at executeDispatch (react-dom.development.js?6ac8:8243)
at processDispatchQueueItemsInOrder (react-dom.development.js?6ac8:8275)
at processDispatchQueue (react-dom.development.js?6ac8:8288)
at dispatchEventsForPlugins (react-dom.development.js?6ac8:8299)
at eval (react-dom.development.js?6ac8:8508)
为什么?