【问题标题】:Unable to start electron through npm [duplicate]无法通过 npm 启动电子 [重复]
【发布时间】:2018-11-01 05:49:36
【问题描述】:

我无法使用npm start 启动我的电子应用程序,但我可以使用 VS Code 的集成调试器启动它。

我的.vscode/launch.json 包含 ff:

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "electron",
      "request": "launch",
      "name": "Launch Electron against the workspace",
      "appDir": "${workspaceFolder}/src/main.js"
    }
    {
      "name": "Debug Main Process",
      "type": "node",
      "request": "launch",
      "cwd": "${workspaceRoot}/src/main.js",
      "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron",
      "windows": {
        "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron.cmd"
      },
      "args" : ["."]
    }
  ]
}

它们都可以正常工作。

但开始使用npm start 不会启动应用程序:

npm info it worked if it ends with ok
npm verb cli [ 'C:\\Program Files\\nodejs\\node.exe',
npm verb cli   'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
npm verb cli   'start',
npm verb cli   '--verbose' ]
npm info using npm@6.4.1
npm info using node@v11.0.0
npm verb run-script [ 'prestart', 'start', 'poststart' ]
npm info lifecycle PRIVATE@0.0.1~prestart: PRIVATE@0.0.1
npm info lifecycle PRIVATE@0.0.1~start: PRIVATE@0.0.1

> PRIVATE@0.0.1 start C:\Users\Test\Desktop\LAN\Workspace\Code\PRIVATE
> electron .

我已经想到了走错路的可能性,但是……

package.json

{
  "name": "...",
  "version": "0.0.1",
  "description": "...",
  "homepage": "...",
  "main": "${workspaceFolder}/src/main.js",
  "directories": {
    "test": "test"
  },
  "scripts": {
    "test": "standard && mocha",
    "start": "electron ."
  },
}

我已经尝试过"start": "electron src/main.js" & "start": "electron src/index.html"

我的src/index.html 包含

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <base href="./">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
  <h1>Test</h1>
</body>
</html>

附注
打开任务管理器,electron 出现,但我的屏幕上什么也没有出现,也没有显示内存/CPU 使用率变化的迹象。与在 VS Code Debugger 中启动它不同,它会立即显示出来。

P.P.S
如果我错过了有关该问题的一些信息,只需将其注释掉,我会尽快将其包含在内。

【问题讨论】:

  • ${workspaceFolder} 可能只在 vscode 中定义,我认为你应该在 package.json 中省略它
  • @rawel 试过了......没有运气
  • 可能值得尝试将 package.json 中的 start 脚本设置为:"start": "node_modules/.bin/electron ."
  • 我不相信 Electron 支持那个版本的 Node.js。尝试将您的节点降级到 10.11。另外,您使用的是什么版本的 Electron?
  • @pushkin 解决了它!。非常感谢。

标签: npm electron


【解决方案1】:

您可以尝试使用 npm run start 吗?

npm run 将 NODE 环境变量设置为执行 npm 的可执行节点

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-10-12
    • 1970-01-01
    • 1970-01-01
    • 2016-12-20
    • 2020-01-21
    • 1970-01-01
    • 1970-01-01
    • 2015-08-22
    相关资源
    最近更新 更多