【问题标题】:Electron not starting properly due to SIGTRAP由于 SIGTRAP,电子无法正常启动
【发布时间】:2022-04-18 01:39:43
【问题描述】:

我进入 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>

ma​​in.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


【解决方案1】:

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

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

如何配置它在这个问题的顶部答案中有解释:How to set up working X11 forwarding on WSL2

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

【讨论】:

    猜你喜欢
    • 2022-07-17
    • 2015-03-03
    • 2021-04-11
    • 1970-01-01
    • 1970-01-01
    • 2020-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多