简体   繁体   English

如何使用源地图远程调试Node.js应用程序(使用WebStorm)

[英]How to remotely debug Node.js app with source maps (using WebStorm)

I struggling to debug remotely piece of node.js code that got translated from ES6 with BabelJs. 我努力地远程调试通过BabelJs从ES6转换过来的node.js代码。 Here's the situation: 情况如下:

I have a project with ES6 source file server\\app.js that gets translated to ES5 and put to dist\\server\\app.js along with dist\\server\\app.js.map . 我有ES6源文件的项目server\\app.js是被翻译成ES5并投入dist\\server\\app.js连同dist\\server\\app.js.map I can set a breakpoint in original server\\app.js and then debug locally file dist\\server\\app.js to hit that breakpoint - source map works perfectly fine. 我可以在原始server\\app.js设置一个断点,然后在本地调试文件dist\\server\\app.js来达到该断点-源映射工作正常。

Now I have put my entire dist folder to remote PC where I start my app with node --debug-brk dist\\server\\app.js command. 现在,我已将整个dist文件夹放入远程PC,在其中使用node --debug-brk dist\\server\\app.js命令启动我的应用程序。 Connecting to that process with remote debugger from WebStorm makes the application run, but the breakpoint is not hit. 使用WebStorm中的远程调试器连接到该进程可以使应用程序运行,但不会遇到断点。

Surprisingly, if I run node --debug-brk dist\\server\\app.js from terminal on the same host where my WebStorm is installed, then remote debugger connecting to localhost:5858 is able to trigger that breakpoint. 出乎意料的是,如果我从安装了WebStorm的同一主机上的终端运行node --debug-brk dist\\server\\app.js ,则连接到localhost:5858的远程调试器将能够触发该断点。

Is there anything that I am missing in order to hit that breakpoint when debugging remotely? 为了远程调试时达到该断点,我是否缺少任何东西?

Thanks in advance for any suggestions. 在此先感谢您的任何建议。

Webstorm: 2016.1
Node: 4.4.2 (both local and remote machine)

When a breakpoint is hit in the communication with WebStorm node debugger seems to send line number and filename. 在与WebStorm节点的通信中遇到断点时,调试器似乎发送行号和文件名。 File path is the the path from the server node is running on. 文件路径是运行服务器节点的路径。 What we have is: 我们拥有的是:

Server (remote):
/remotePath/dist/server/app.js (transpiled file ES5)

Local system:
/localPath/server/app.js (source file ES6)
/localPath/dist/server/app.js (transpiled file ES5)
/localPath/dist/server/app.js.map (source map).

What node is sending back is this path: 该节点发送回的路径是:

/remotePath/dist/server/app.js

So WebStorm tries to find this file in its file system. 因此,WebStorm尝试在其文件系统中找到此文件。 But it doesn't exist. 但是它不存在。 The solution here could be to create a symbolic link in the local file system: 此处的解决方案可能是在本地文件系统中创建符号链接:

/remotePath -> /localPath

Btw. 顺便说一句。 VS Code has it solved by exposing localRoot and remoteRoot in debug configuration. VS Code通过在调试配置中公开localRoot和remoteRoot来解决它。

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

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