【问题标题】:Visual Studio Code unable to debug ElectronVisual Studio Code 无法调试 Electron
【发布时间】:2017-09-26 16:36:28
【问题描述】:

我在 Windows 8 上的 Visual Studio Code 上使用 Electron。我是 Electron 新手。
我使用了electron-quick-start,它在与 VS Code 终端一起运行时在 Visual Studio Code 中工作。但是当我尝试调试代码时,出现以下错误:

Debugger listening on [::]:46522
e:\Projects\BT\electron-quick-start\main.js:40
app.on('ready', createWindow)
   ^

TypeError: Cannot read property 'on' of undefined
    at Object.<anonymous> (e:\Projects\BT\electron-quick-start\main.js:40:4)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Timeout.Module.runMain [as _onTimeout] (module.js:604:10)
    at ontimeout (timers.js:365:14)
    at tryOnTimeout (timers.js:237:5)
    at Timer.listOnTimeout (timers.js:207:5)

当调试器到达 main.js 中的以下行时发生错误:

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow)

我完全使用electron-quick-start 中的代码。这意味着对于 package.json:

{
  "name": "electron-quick-start",
  "version": "1.0.0",
  "description": "A minimal Electron application",
  "main": "main.js",
  "scripts": {
    "start": "electron ."
  },
  "repository": "https://github.com/electron/electron-quick-start",
  "keywords": [
    "Electron",
    "quick",
    "start",
    "tutorial",
    "demo"
  ],
  "author": "GitHub",
  "license": "CC0-1.0",
  "devDependencies": {
    "electron": "~1.6.2"
  }
}

我需要做什么才能在 Visual Studio Code 中调试此代码

【问题讨论】:

  • 正如我所说,当我使用终端运行它时它确实有效:VSCode 内部和外部。问题是尝试使用 VSCode 进行调试时
  • 您确定在两个终端上使用相同的命令吗?你用的是什么终端?命令?电源外壳? WSL?
  • 是的。我在 Windows 8 中使用 cmd 在 VS Code 之外调用它,而在 VS Code 中我使用集成终端。对于这两者,我都使用命令“npm start”,它在它们两者中都有效。当我尝试调试时出现问题
  • 并且集成终端设置为使用cmd?
  • 是的。设置cmd

标签: node.js visual-studio-code electron


【解决方案1】:

这表明这是一个全球性问题,已在 VS Code 的新更新 1.17.2 中得到修复。所以我不知道为什么有些人已经降级了这个问题,虽然这是一个相关的问题,为什么 stackoverflow 允许这样做,但是对于所有遇到这个问题的人,我发布了这个答案。
安装新的更新 1.17.2 后,问题得到解决。 VS Code 在 1.17 版本中解决了这个问题。 Here 是有关功能和错误修复的一些信息(包括 VS Code 中的电子功能)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-04
    • 2015-10-11
    • 2017-12-18
    • 1970-01-01
    • 2021-02-01
    • 1970-01-01
    • 2020-06-09
    • 2022-06-24
    相关资源
    最近更新 更多