You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ElectronJS运行报错:Cannot read properties of undefined (reading 'whenReady')

报错原因
  • 你使用node命令直接运行Electron主进程代码是根本诱因:Electron的专属API只能在Electron运行时环境中调用,普通Node.js环境下执行require('electron')返回的是Electron可执行文件的路径字符串,而非Electron运行时暴露的内置模块对象,因此解构得到的app为undefined,调用app.whenReady自然会抛出属性读取错误。
  • 你给出的依赖版本本身没有兼容性问题,代码逻辑也没有错误,问题完全出在启动方式上。
解决方法
  1. 先确认项目根目录的package.json配置正确,参考示例:
{
  "name": "term-record",
  "version": "1.0.0",
  "main": "src/render.js",
  "scripts": {
    "start": "electron ."
  },
  "dependencies": {
    "electron": "16.0.1"
  }
}
  1. 放弃原有的node src/render.js启动命令,改用以下任意一种方式启动:
    • 执行npm run start调用项目本地安装的Electron运行代码
    • 若你全局安装了Electron,也可以直接执行electron src/render.js启动

内容的提问来源于stack exchange,提问作者Aditya

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.25 12:15:01