简体   繁体   English

VS Code Node.js macOS 调试不起作用 - 我什至不知道如何说明问题

[英]VS Code Node.js macOS debugging not working - I don't even know how to state the problem

Newbie question here, it seems... I'm losing my mind.新手问题在这里,似乎......我失去了理智。 Why is this so hard?为什么这么难? I've been programming other languages for years, but I'm relatively new to node and JS.我多年来一直在编写其他语言,但我对 node 和 JS 比较陌生。 I've read and watched as much as I can find official and unofficial on the web about this and it's either years old or significantly different from my situation, so not very helpful.我已经阅读和观看了尽可能多的关于这方面的官方和非官方网站,它要么是几年前的,要么与我的情况有很大不同,所以不是很有帮助。

I'd really, really appreciate anyone who can understand my (pretty simple, I would have thought!?) specific case and help me get this set up to just work.我真的非常感谢任何能够理解我的(很简单,我会想!?)具体案例并帮助我设置正确工作的人。 Possible?可能的?

  • macOS 10.15.6 Catalina. macOS 10.15.6 卡特琳娜。
  • As I understand it, node comes with the OS.据我了解,节点随操作系统一起提供。 It's Node.js 12.8.1这是 Node.js 12.8.1
  • VS Code 1.48.2 VS 代码 1.48.2

I create a new file, name it abcd.js.我创建了一个新文件,将其命名为 abcd.js。 VS Code figures out it's javascript. VS Code 发现它是 javascript。 I add some code - read a file of JSON from the disk, make some changes, console.log some stuff (appears under the Output tab).我添加了一些代码 - 从磁盘读取一个 JSON 文件,进行一些更改,console.log 一些东西(出现在输出选项卡下)。 I run it.* All good and works.我运行它。* 一切正常,工作正常。

Now... Run menu > "Start Debugging".现在...运行菜单>“开始调试”。 Or, There's a Run/Debug icon in the sidebar that shows a "Run and Debug" button which I click on.或者,侧栏中有一个运行/调试图标,显示我单击的“运行和调试”按钮。 Both of those ask me for an environment - I choose Node.js, and the Debug console outputs this:两者都要求我提供环境 - 我选择 Node.js,调试控制台输出如下:

/usr/local/bin/node path/to/my/file.js
Debugger listening on ws://127.0.0.1:56430/30b0c2aa-278b-4540-94c4-825d30b94f57
For help see https://nodejs.org/en/docs/inspector

And that's it.就是这样。 I have breakpoints, but it doesn't stop on them.我有断点,但它并没有停止。 Something happens (too quick to see what it is).发生了一些事情(太快了,看不出是什么)。 I don't think it's actually running my code because nothing new shows up under the Output tab.我认为它实际上并没有运行我的代码,因为“输出”选项卡下没有显示任何新内容。

There's also a note in that sidebar saying "To customize Run and Debug create a launch.json file."该侧边栏中还有一条注释,上面写着“要自定义运行和调试,请创建一个 launch.json 文件”。 I've experimented with that as much as I can, but nothing I do seems to help.我已经尽可能多地尝试过,但我所做的一切似乎都无济于事。

I've been programming for years.我已经编程多年了。 I'm used to other languages and IDEs (eg. C, Java, AppleScript, Swift, others), where you open the IDE, write some code, hit run (or debug), it may or may not build a target (depending on the language and environment), but then it runs the code (opens the target app, or runs in the IDE, and allows you to step through the code, breakpoints, etc. in the IDE if debugging).我习惯于其他语言和 IDE(例如 C、Java、AppleScript、Swift 等),在其中打开 IDE,编写一些代码,点击运行(或调试),它可能会或可能不会构建目标(取决于语言和环境),然后运行代码(打开目标应用程序,或在 IDE 中运行,并允许您在调试时在 IDE 中单步执行代码、断点等)。 Is JS/node programming radically different from this somehow? JS/节点编程是否与此完全不同?

*One theory: *一种理论:

I'm not doing this through any terminal or any browser.我不是通过任何终端或任何浏览器执行此操作。 Maybe that's the problem...?也许这就是问题所在......? At some point I installed a "Code Runner" plugin that I believe is what is running my code.在某些时候,我安装了一个“Code Runner”插件,我相信它是运行我的代码的东西。 It was a while ago, but if I recall correctly maybe I turned to that because I was looking for the experience I've described above, and this plugin gave me that where the "normal" node setup process didn't?那是前一段时间,但如果我没记错的话,也许我转向了那个,因为我正在寻找我上面描述的体验,而这个插件给了我“正常”节点设置过程没有的地方? Perhaps my problem is that that plugin simplifies RUNNING js scripts so much that my issues with DEBUGGING exist because that plugin allows me to bypass other usual complications with running JS/Node scripts (but doesn't have any debugging functionality of its own)?也许我的问题是该插件极大地简化了 RUNNING js 脚本,以至于我的调试问题存在,因为该插件允许我绕过其他常见的运行 JS/Node 脚本的复杂问题(但它自己没有任何调试功能)?

My thanks to @ippi for his/her comment with a gif video.感谢@ippi 对 gif 视频的评论。 Not sure if the following really answers my question, but I'm posting it in case it helps anyone else.不确定以下内容是否真的回答了我的问题,但我将其发布以防对其他人有所帮助。

I took some time to clean up my Mac a little, and I completely uninstall VSCode, all its extensions and supporting files and started again.我花了一些时间来清理我的 Mac,然后我完全卸载了 VSCode、它的所有扩展和支持文件,然后重新开始。

I re-installed Code from scratch, didn't add any extensions, and then tried what @ippi's video showed.我从头开始重新安装 Code,没有添加任何扩展,然后尝试了@ippi 视频显示的内容。

It still didn't work - I got more or less the same output as in my post, and I'm not sure if it was running the code or not.它仍然不起作用 - 我得到的输出与我的帖子中的输出大致相同,我不确定它是否正在运行代码。

I had an urgent deadline to meet so didn't come back to it till now - two days later - and now, it's working.我有一个紧迫的截止日期要满足,所以直到现在 - 两天后才回来 - 现在,它正在起作用。

A couple of things changed in that time though I really don't know what fixed this, if it was either of those or anything else.在那段时间里发生了一些变化,尽管我真的不知道是什么解决了这个问题,如果是这些或其他任何原因。 The two changes I can remember that I've done the last two days are:我记得我最近两天所做的两个更改是:

  1. Despite my post saying my node was 12.8.1, sometime in the last couple of days it turned into 8.something.尽管我的帖子说我的节点是 12.8.1,但在过去几天的某个时候它变成了 8.something。 I updated it to the latest v12.8.3, and我将其更新到最新的 v12.8.3,并且
  2. to meet that deadline I used node inspect myfile.js in Terminal for a bit.为了满足这个截止日期,我在终端中使用了node inspect myfile.js一段时间。

The inspect (mostly) worked to meet my deadline, but still a hassle compared to what's shown in @ippi's video. inspect (主要是)努力满足我的最后期限,但与@ippi 视频中显示的内容相比仍然很麻烦。 I definitely wanted to get it working that way.我绝对想让它以这种方式工作。

So… updating node fixed it?那么……更新节点修复了吗? Running it in the terminal for a bit fixed it?在终端中运行它有点修复它? Something else?还有什么? I'm at a loss to know what did it.我不知所措。 But it's working now.但它现在正在工作。

Thanks again to @ippi for that.再次感谢@ippi。 It pointed me in a good direction at least - to clean up my install a bit, if nothing else.它至少为我指明了一个好的方向 - 稍微清理一下我的安装,如果没有别的。

Maybe this will help someone else sometime in the future.也许这会在将来的某个时候帮助其他人。


It seems the ultimate answer is:似乎最终的答案是:

It should just work out of the box (possibly subject to updating node to its latest).它应该是开箱即用的(可能需要将节点更新到最新版本)。 If it doesn't then:如果没有,那么:

  • The issue most likely isn't that you have to do any fancy configuring or whatnot to make it work.问题很可能不是您必须进行任何花哨的配置或其他什么才能使其工作。

  • Instead, most likely something is wrong with your installation and/or OS and you should explore that.相反,您的安装和/或操作系统很可能有问题,您应该探索一下。


@ippi's video attached in case his/her link ever breaks:附上@ippi 的视频,以防他/她的链接中断:

@ippi 的 gif

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果我不知道参数数量(JS,Node.js),如何编写函数 - how to write a function if I don't know number of parametrs (JS, Node.js) 我正在尝试使用node.js将文件上传到AWS,但我不知道我的代码出了什么问题 - I'm try to upload file using node.js to aws but i don't know what went wrong with my code Node.js stacktraces不包含用户代码 - Node.js stacktraces don't include user code 让VS代码调试js代码时默认选择Node.js环境 - Make VS code choose Node.js environment by default when debugging js code 嘿,当使用 node.js 从 html 表单将数据插入 MySql 时,我不知道从哪里开始 - Hey I don't know where to start when inserting data into MySql from html form using node.js 当您不知道页数时,如何在使用Node.js的while循环中向API发出多个分页的GET请求? - How to make multiple paginated GET requests to an API in while loop with Node.js when you don't know the page count? 我的代码在第5行有一个问题,说“Missing'()'调用一个构造函数”,我不知道如何调试 - There is a problem in my code on line 5 stating “Missing '()' invoking a constructor” and i don't know how to debug that 不知道如何在节点中运行app.js. - Don't know how to run app.js in node 如果我有应用程序的源代码和 macOS 和 Windows 安装程序,我如何才能找到用于构建应用程序的 Node.js 版本? - if I have source code and macOS and Windows installers for an app, how can I find what version of Node.js was used to build the app? 我想知道如何在 Node.JS 中处理 POST 请求 - I want to know how to handle POST requests in Node.JS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM