Electron 由于 SIGTRAP 无法正常启动

问题描述 投票:0回答:2

我正在进入 Electron,尝试开始构建桌面应用程序。我遇到了这个错误:

/home/me/dev/my-electron-app-2/node_modules/electron/dist/electron exited with signal SIGTRAP

这条路径通向一个二进制文件,所以我无法真正读取正在发生的事情。当我运行时出现此错误:

npm start

我的目标是在我的桌面上出现一个反映 HTML 页面的窗口。到目前为止,该应用程序只是:

index.html

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP -->
    <meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'">
    <meta http-equiv="X-Content-Security-Policy" content="default-src 'self'; script-src 'self'">
    <title>Hello World!</title>
  </head>
  <body>
    <h1>Hello World!</h1>
    We are using Node.js <span id="node-version"></span>,
    Chromium <span id="chrome-version"></span>,
    and Electron <span id="electron-version"></span>.
  </body>
</html>

main.js

const { app, BrowserWindow } = require('electron')

const createWindow = () => {
    const win = new BrowserWindow({
      width: 800,
      height: 600
    })
  
    win.loadFile('index.html')
}

app.whenReady().then(() => {
    createWindow()
  })

此代码来自文档,此处:https://www.electronjs.org/docs/latest/tutorial/quick-start

我在谷歌上搜索了很多,但无法找到一个有效的解决方案。我在 WSL 中使用 Ubuntu。如果有人有任何建议,我们将不胜感激。

谢谢

javascript npm electron windows-subsystem-for-linux desktop-application
2个回答
0
投票

由于 Electron 是一个 GUI 应用程序,并且您在 WSL 上使用 Ubuntu(我假设是 WSL2?),因此您需要为 Ubuntu 运行 X 服务器,以便在其上呈现 GUI。

您可以从这里下载并安装VcXsrv:https://sourceforge.net/projects/vcxsrv/

此问题的最佳答案中解释了如何配置它:如何在 WSL2 上设置工作 X11 转发

您的另一个选择是不使用 WSL;只需直接在 Windows 机器上运行 Node、npm 和 Electron 即可。然后,您将不需要安装任何单独的 X 服务器;你的应用程序应该可以正常工作。


0
投票

导致此错误的问题只是我需要更改 package.json 中的“main”条目:

"main": "main.js",

© www.soinside.com 2019 - 2024. All rights reserved.