简体   繁体   English

如何使用JavaScript断点进行调试WebStorm

[英]How to debug with JavaScript breakpoints WebStorm

In WebStorm 6's debugger panel I see this: 在WebStorm 6的调试器面板中,我看到以下内容:

在此处输入图片说明

What I must do to get these breakpoints to work? 我必须怎么做才能使这些断点正常工作?

I found that using 'debugger' at a point somewhere ahead of where I needed to actually hit a breakpoint was enough to actually get this working for a 'local' debug session. 我发现在实际需要达到断点之前的某个位置使用“调试器”足以使此调试器实际用于“本地”调试会话。 Without that, it didn't matter what I did, the webstorm-running-node engine would just simply run my javascript, completely ignoring breakpoints. 没有它,我做什么都没关系,webstorm-running-node引擎将只运行我的javascript,而完全忽略断点。

Here's a dummy example. 这是一个虚拟的例子。 I could not get the debugger to ever stop at the breakpoint at line 20. I put in the 'debugger;' 我无法使调试器永远停在第20行的断点处。我放入了“调试器”。 entry above it, and everything started working again. 条目上方,一切又重新开始工作。 If I take it out, it stops working, which is a pain, but it lets me get on with my work for now. 如果将它取出,它会停止工作,这很痛苦,但是现在让我可以继续工作。 Sooner or later I am going to accidentally leave one of them in when I do a deployment tho... :\\ 早晚进行部署时,我会不小心将其中一个留给...:\\

“调试器”用法示例

You have to use remove debugging and you have to supply an mapping for the urls in the debug configuration so that webstorm can find the files. 您必须使用删除调试,并且必须在调试配置中提供URL的映射,以便Webstorm可以找到文件。

This can be done via "Run" / "Edit Configurations ...". 这可以通过“运行” /“编辑配置...”来完成。 In there click on your projects base dir and double-click on the right side to enter text. 在其中单击项目的基本目录,然后双击右侧以输入文本。

If your files are eg in "mydir/html/workspace/Project/" and are accessible via "http://localhost/Project" then enter "http://localhost/Project/" . 如果您的文件位于"mydir/html/workspace/Project/" ,并且可以通过"http://localhost/Project"则输入"http://localhost/Project/"

You will notice that now when you click on an log entrie the file which opens is your local one which you can edit while it was the remote one before. 您会发现,当您单击一个日志条目时,打开的文件就是您的本地文件,您可以在本地文件之前对其进行编辑。

I'm using Webstorm 2019.2 and I was able to set up debugging with breakpoints for a basic react app created with create-react-app as follows: 我正在使用Webstorm 2019.2,并且能够为使用create-react-app创建的基本react应用设置断点调试功能,如下所示:

  1. Run npm start to get the app running in the development mode. 运行npm start以使应用程序在开发模式下运行。 You can do this either in the terminal or by double-clicking the task in the npm tool window in WebStorm. 您可以在终端中或通过在WebStorm的npm工具窗口中双击任务来执行此操作。
  2. Create a new JavaScript debug configuration in WebStorm (menu Run – Edit configurations… – Add – JavaScript Debug). 在WebStorm中创建新的JavaScript调试配置(菜单运行–编辑配置…–添加– JavaScript调试)。 Paste http://localhost:3000/ into the URL field. http:// localhost:3000 /粘贴到URL字段中。

    • VERY IMPORTANT : Check the box "Ensure breakpoints are detected when loading scripts" because it's not selected by default and my breakpoints didn't work with out it. 非常重要 :选中“确保在加载脚本时检测到断点”框,因为默认情况下未选中它,而我的断点也无法使用。
  3. Click OK to close Run/Debug Configurations 单击“确定”关闭“运行/调试配置”

  4. Set some breakpoints 设置一些断点

  5. Select the new run config from the drop down box next to the Play button 从“播放”按钮旁边的下拉框中选择新的运行配置

  6. Press the bug button next to the play button 按下播放按钮旁边的错误按钮

  7. Breakpoints should fire now once the web browser comes up and you reach the code that's got breakpoints 一旦浏览器启动,断点现在应该触发,您可以找到有断点的代码

Some of this came from Debugging React apps created with Create React App in WebStorm 其中一些来自调试使用WebStorm中的Create React App创建的React应用程序

For a pretty good demonstration see Debugging JavaScript in WebStorm and Chrome: create a debug configuration but don't forget the VERY IMPORTANT step above. 有关很好的演示,请参阅在WebStorm和Chrome中调试JavaScript:创建调试配置,但不要忘记上面的“ 非常重要”步骤。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM