gpt4 book ai didi

javascript - 使用 Webstorm 调试 Nodewebkit

转载 作者:行者123 更新时间:2023-11-27 23:32:45 25 4
gpt4 key购买 nike

我正在尝试在 Webstorm 中打开 NW,以便可以开始调试。当我在应用程序中出现错误时,NW 窗口就会关闭,没有任何提示为什么会发生这种情况。

我找到了这个article在网络 Storm 网站上。在我的根文件夹中,我有 app.js,其中包含常用的快速应用程序启动和模块包含。我还有 package.json:

{
"name": "nw",
"version": "1.0.0",
"description": "",
"main": "index.html",
"node-main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"window": {
"toolbar": true,
"width": 800,
"height": 500
},
"license": "ISC",
"dependencies": {
"jquery": "^2.1.4",
"nw": "^0.12.2",
"pretty-bytes": "^1.0.2"
}
}

我有以下index.html 文件:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My App</title>
<script src="app.js" type="text/javascript"></script>
</head>
<body>
<script type="text/javascript">
window.location = 'http://localhost:3000';
</script>
</body>
</html>

我对此有两个问题:

  1. 当我单独运行 NW 时(只需双击 nw.exe),应用程序将启动,但并非总是如此。 10次​​后,只会关闭3次。其余的都可以正常打开。

  2. 我按照 Webstorm 网站上的说明进行了调试,结果很奇怪。当我尝试在 webstorm 中打开它时,NE 窗口显示,并立即关闭并显示此错误:进程已完成,退出代码 0但我可以在正常模式(不是 Debug模式)下在 webstorm 中打开应用程序。

这里发生了什么?我的 Webstorm 调试屏幕: enter image description here

最佳答案

您没有发布任何代码,但您可能会遇到导致应用程序立即崩溃的异常。

根据过去的经验,最常见的异常是由于不正确的窗口调用引起的:

window: defined as a property of 'global', points to the DOM window global object. Note that it would be updated upon page navigation. This symbol is not available at the time the script is loaded, because the script is executed before the DOM window load (source)

因此,如果您使用“node-main”并在其中使用“window”,您的应用程序将在启动时崩溃。在 app.js 中查找对 window 的任何调用并尝试对其进行注释。如果它有效 - 您需要将代码放入函数中并从 index.html 调用它们。

如果情况并非如此,您需要调试代码以找出其中断的原因。尝试省略代码块来查找错误。您可以发布您的代码以获得更多帮助。

关于javascript - 使用 Webstorm 调试 Nodewebkit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34411426/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com