VSCode 为 eggjs 配置远程调试

本文将介绍如何在 VSCode 中为 eggjs 配置远程调试。

笔者的开发框架是这样的:源码位于 wsl 中,然后将源代码挂载到 Docker 容器内部,容器负责开发环境的运行。在开发时,使用 VSCode 远程到 wsl,然后打开源码目录进行开发。

配置步骤

  1. 将 eggjs 中的远程调试端口 9999 暴露到主机中

    按官方介绍,默认的调试端口应该是 9229,但是在实测中,该端口未启用,而是使用了 9999

  2. .vscode/launch.json 中,添加如下配置

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    {
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
    {
    "type": "node",
    "request": "attach",
    "name": "Remote Egg Debug",
    "address": "127.0.0.1",
    "port": 9999,
    "restart": true,
    // 本地程序所在的目录
    "localRoot": "/home/xxx/app/docker-dev-envs/eggjs",
    // 服务器对应程序所在的目录
    "remoteRoot": "/app/eggjs"
    }
    ]
    }

参考

本文参考以下文章,在此致以诚挚谢意!

Node.js — Debugging Node.js

vscode本地debug远程,出现错误,期望获取正确的debug方式 · Issue #4700 · eggjs/egg