Electron无法启动报NODE_OPTIONs错误,多次重装未解决求助
Electron应用无法启动,报错NODE_OPTIONs不支持
错误信息
[6520:0618/131330.291:ERROR:node_bindings.cc(332)] Most NODE_OPTIONs are not supported in packaged apps. See documentation for more details. [6520:0618/131330.291:ERROR:node_bindings.cc(332)] Most NODE_OPTIONs are not supported in packaged apps. See documentation for more details. [6520:0618/131330.292:ERROR:node_bindings.cc(332)] Most NODE_OPTIONs are not supported in packaged apps. See documentation for more details. [6520:0618/131330.292:ERROR:node_bindings.cc(332)] Most NODE_OPTIONs are not supported in packaged apps. See documentation for more details.
相关代码
package.json
{ "name": "thungy", "private": true, "main": "electron.js", "scripts": { "start": "electron ." }, "dependencies": { "electron": "^25.1.1" } }
electron.js
const { screen, app, BrowserWindow } = require("electron"); const path = require("path"); app.on("ready", () => { const { height, width } = screen.getPrimaryDisplay().workAreaSize; const window = new BrowserWindow({ titleBarStyle: "hidden", height: height, width: width, center: true, webPreferences: { nodeIntegration: true, contextIsolation: false } }); window.loadFile(path.join(__dirname, "/public/index.html")); });
修复步骤
- 排查系统环境变量:
Windows打开命令提示符执行echo %NODE_OPTIONS%,Linux/macOS打开终端执行echo $NODE_OPTIONS,如果输出内容,说明全局设置了Electron不支持的Node选项,直接删除该环境变量。 - 检查启动命令:
确认启动时没有额外传递NODE_OPTIONS参数,比如不要用NODE_OPTIONS=xxx npm start,直接运行npm start即可。 - 检查项目配置:
查看项目中是否用cross-env等工具设置了NODE_OPTIONS,如有则移除相关配置。
你的代码本身无问题,错误源于外部的Node选项配置,和重装Electron无关。
内容的提问来源于stack exchange,提问作者JavaBruhipt
相关产品推荐
相关产品推荐

