简体   繁体   English

WebStorm使用Babel远程调试NodeJS

[英]WebStorm remote debugging NodeJS with Babel

I'm running my node application with: 我正在运行我的节点应用程序:

"./node_modules/nodemon/bin/nodemon.js --ignore ./build/* ./bin/www --exec babel-node --debug=7001",

When I connect with a WebStorm remote configuration it seems to work, but the placing breakpoint results in either them being ignored, or the code actually stop at different lines. 当我连接WebStorm远程配置时它似乎工作,但放置断点导致它们被忽略,或者代码实际上停在不同的行。

This is probably due to Babel transpiling. 这可能是由于巴贝尔的转变。 How can I do that, given my code is transpiled at runtime? 鉴于我的代码是在运行时编译的,我怎么能这样做呢?

My .babelrc file: 我的.babelrc文件:

{
  "presets": ["es2015", "stage-2"],
  "plugins": ["transform-runtime"]
}

Here is the revelent documentation : https://blog.jetbrains.com/webstorm/2015/05/ecmascript-6-in-webstorm-transpiling/ 以下是令人瞩目的文档: https ://blog.jetbrains.com/webstorm/2015/05/ecmascript-6-in-webstorm-transpiling/

If you'd like to debug your code using WebStorm or Chrome, make sure the tools you're using generates source maps . 如果您想使用WebStorm或Chrome调试代码,请确保您使用的工具生成源地图 For example, when using Babel only, you need to add "sourceMaps": "both" option to your .babelrc file or pass it as a command-line argument. 例如, 当仅使用Babel时,您需要在.babelrc文件中添加“sourceMaps”:“both”选项或将其作为命令行参数传递。 If you're using Babel as a part of a more complex build process, you might need a addition configuration for generating source maps, eg use gulp-sourcemaps with Gulp or add devtool: "source-map" option when using Webpack. 如果您使用Babel作为更复杂构建过程的一部分,则可能需要一个用于生成源映射的附加配置,例如,在使用Webpack时使用gulp-sourcemaps和Gulp或添加devtool:“source-map”选项。

Source maps allow you to put breakpoints in the original source files in the IDE and be sure that they are hit then compiled code is executed in the browser. 源映射允许您将断点放在IDE中的原始源文件中,并确保它们被命中,然后在浏览器中执行已编译的代码。

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

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