使用Express应用程序和Babel 7进行VS代码调试

时间:2019-05-03 16:56:34

标签: javascript express visual-studio-code babeljs vscode-debugger

我正在尝试在与Experss服务器(REST API)一起使用VS Code中进行调试。我已经尝试了几种launch.json配置,阅读了文档以及有关Stankoverflow的几篇文章,包括VS Code: help debugging angular 2 with express,但是没有运气。这是我的项目结构和配置

|-.vscode
|-config
|-db
|-dist
|-routes
|-server
  |
  |-index.js // entry point

我正在将JavaScript文件与es6 / 7与Babel 7进行反编译。源映射由Babel生成,并位于相关文件(即同一目录)的旁边。

Babel从npm脚本中调用

"transcompile": "babel . -d dist --ignore node_modules --source-maps",

.babelrc

{
  "presets": ["@babel/preset-env"],
  "plugins": [
    "@babel/plugin-transform-runtime",
  ],
  "sourceMaps": "both",
  "highlightCode": true,
}

我的配置是

launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "server",
            "program": "${workspaceFolder}/dist/server/index.js",
            // "program": "${workspaceFolder}/server/index.js",
            "smartStep": true,
            "outFiles": [
                "${workspaceRoot}/dist/**/*.js",
                "${workspaceRoot}/dist/*.js"                
            ],
            "env": {
                "NODE_ENV": "devLocal"
            },
            "protocol": "inspector",
            "skipFiles": [
                "${workspaceFolder}/dist/server/node_modules/**/*.js",
                "<node_internals>/**/*.js",
            ]
        },
    ]
}



Outcome of running debugger
> If "program" points to original source: Debugger starts and then just stops. No sign that the app ran and no errors.
> If "program" points to /dist: Debugger & App starts. Doesn't hit brakepoint from initial load. Does hit breakpoint when calling API from browser. However, stepping doesn't follow the expected course (i.e., stepping through the code I wrote). It goes into files in /node_modules and never turns to my code. This is true even using step-over (shift+F11).


In addition to overall what needs to change in the configuration to get things working, I'm also wondering the following
- Do I need "program"
- Should "program" point to the original source ("${workspaceFolder}/server/index.js") or to /dist ("${workspaceFolder}/dist/server/index.js")
- Do I need "skipFiles" since "smartStep" is set?
- ... and should "skipFiles" point to the original source or /dist




0 个答案:

没有答案