vscode如何调试使用eggjs构建的应用中node代码?

1、用eggjs构建的项目,目录结构如下:

clipboard.png

其中app是后台部分,static是前端页面,我想要调试app其中的node代码,按照提示配置了launch.json,

clipboard.png

clipboard.png

打了断点运行后没有在断点处停下来,还是没法调试,求教正确调试node的姿势,谢谢!

经@Leo_ 指路,配置好launch.json后,出现了下面的错误:

clipboard.png

阅读 6.9k
3 个回答

文档里面写的很清楚啊
使用egg-development-proxyworker这个插件,vscode的配置应该是这样的

  "version": "0.2.0",
  "configurations": [
    {
      "name": "Launch Egg",
      "type": "node",
      "request": "launch",
      "cwd": "${workspaceRoot}",
      "runtimeExecutable": "npm",
      "windows": {
        "runtimeExecutable": "npm.cmd"
      },
      "runtimeArgs": [
        "run", "dev", "--", "--debug"
      ],
      "protocol": "legacy",
      "port": 5858
    },
    {
      "name": "Attach Agent",
      "type": "node",
      "request": "attach",
      "port": 5856
    },
    {
      "name": "Attach Worker",
      "type": "node",
      "request": "attach",
      "restart": true,
      "port": 10086
    }
  ],
  "compounds": [
    {
      "name": "Debug Egg",
      "configurations": ["Launch Egg", "Attach Agent", "Attach Worker"]
    }
  ]
}

我解决了.
我也遇到了跟你类似的问题.
仅供你参考
egg 文档

// .vscode/launch.json
{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Launch Egg",
      "type": "node",
      "request": "launch",
      "cwd": "${workspaceRoot}",
      "runtimeExecutable": "npm",
      "windows": { "runtimeExecutable": "npm.cmd" },
      "runtimeArgs": [ "run", "debug" ],
      "console": "integratedTerminal",
      "protocol": "auto",
      "restart": true,
      "port": 9999
    }
  ]
}

其中主要问题在port: 9999
改成你相应的 debugPort 就行
你可以在命令行里 输入: npm debug
会输出类似的内容:

Debugger attached.
2017-09-28 14:56:28,678 INFO 1933 [egg-development-proxyworker] client worker ready to connect proxyworker.
2017-09-28 14:56:28,681 INFO 1932 [egg-development-proxyworker] debugger attached
2017-09-28 14:56:28,682 INFO 1932 [egg-development-proxyworker] debugger debugPort is 9230
2017-09-28 14:56:28,682 INFO 1932 [egg-development-proxyworker] debugger proxyPort is 10086
2017-09-28 14:56:28,682 INFO 1932 [egg-development-proxyworker] debugger wsProxyPort is 10087
2017-09-28 14:56:28,838 INFO 1934 [egg-development-proxyworker][ws] debugger listen at 10087
debugPort is 9230

我改成9230就可以用了.


 "configurations": [
    {
        ......
      "port": 9230
    }

FYI

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题