node.js - 类型错误 : Cannot read property 'showMessageBox' of undefined electron in node js

标签 node.js express electron

下面的代码只是使用 Electron Node 模块显示对话框。

app.js

    const { dialog } = require('electron')
    const response = dialog.showMessageBox(null);
    console.log(response);

需要帮助以了解为什么我收到以下错误消息:
    const response = dialog.showMessageBox(null);
                            ^
    TypeError: Cannot read property 'showMessageBox' of undefined
        at Object.<anonymous> (C:\Users\1217688\Desktop\WebApp\node-elect-test\app.js:2:25)
        at Module._compile (module.js:660:30)
        at Object.Module._extensions..js (module.js:671:10)
        at Module.load (module.js:573:32)
        at tryModuleLoad (module.js:513:12)
        at Function.Module._load (module.js:505:3)
        at Function.Module.runMain (module.js:701:10)
        at startup (bootstrap_node.js:190:16)
        at bootstrap_node.js:662:3

最佳答案

在渲染器进程中,添加 .remote

const { dialog } = require('electron').remote

关于node.js - 类型错误 : Cannot read property 'showMessageBox' of undefined electron in node js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55761223/

相关文章:

javascript - Electron 打包后不支持 ES6

electron - NeutralinoJS 和 Tauri 后端服务

node.js - AngularJS:Karma + Jasmine 使用 _real_ 后端进行测试

javascript - 连接到我的 Visual Studio Online API 返回 HTTP 302

javascript - 将 GraphiQL 查询转换为 JSON

node.js - 如何使用日期字段按周、小时和天过滤文档

electron - 开始菜单中使用的Electron Appx默认 Electron 图标

node.js - 使用 Express 的简单子(monad)域

node.js - undefined 不是一个对象(评估 'this.login().bind' )

angular - 是否可以使用 Angular 拦截器拦截像 .html 这样的静态文件?我想改变 lang 属性