[eggjs/egg]用 vscode debug 显示错误

2025-11-20 756 views
5
描述1
mac (f5) 点击debug的时候爆出的错误,全新项目。卡住没有跑到127.0.0.1:7001里面。
有时候跑到,也会乱debug。

cd /Users/xjc/my-project/test/egg-test ; /Users/xjc/n/bin/npm run debug -- --inspect-brk                                         xjc@xjcdeMacBook-Pro

> test@1.0.0 debug /Users/xjc/my-project/test/egg-test
> egg-bin debug "--inspect-brk"

Debugger listening on ws://127.0.0.1:9229/102d871e-07ae-4f14-a68d-7a962c677d4b
For help see https://nodejs.org/en/docs/inspector
Debugger attached.
[egg-ts-helper] create typings/app/controller/index.d.ts (4ms)
[egg-ts-helper] create typings/config/index.d.ts (18ms)
[egg-ts-helper] create typings/config/plugin.d.ts (2ms)
[egg-ts-helper] create typings/app/index.d.ts (1ms)
2019-04-08 20:51:52,380 INFO 60743 [master] node version v9.11.2
2019-04-08 20:51:52,382 INFO 60743 [master] egg version 2.20.2
Debugger listening on ws://127.0.0.1:5800/641ccb34-46de-4220-8569-f66449342a10
For help see https://nodejs.org/en/docs/inspector
描述2
最新版本vscode,node js 9.x, 10.x,11.x 都试过不行。
描述3
执行 autod 等其他信息。

[DEPENDENCIES]

  "dependencies": {
    "egg": "^2.20.2",
    "egg-scripts": "^2.11.0"
  },
  "devDependencies": {
    "autod": "^3.1.0",
    "autod-egg": "^1.1.0",
    "egg-bin": "^4.12.2",
    "egg-ci": "^1.11.0",
    "egg-mock": "^3.22.1",
    "eslint": "^5.16.0",
    "eslint-config-egg": "^7.3.1",
    "webstorm-disable-index": "^1.2.0"
  }
Dependencies updates

Package Name   Old Version   Latest Version
egg            ^2.15.1       ^2.20.2       

DevDependencies updates

Package Name        Old Version   Latest Version
egg-mock            ^3.21.0       ^3.22.1       
egg-bin             ^4.11.0       ^4.12.2       
autod               ^3.0.1        ^3.1.0        
eslint              ^5.13.0       ^5.16.0       
eslint-config-egg   ^7.1.0        ^7.3.1        

[INFO] Write dependencies into package.json.
描述4
请求更详细的教程
官网https://eggjs.org/zh-cn/core/development.html#%E4%BD%BF%E7%94%A8-egg-bin-%E8%B0%83%E8%AF%95 服务器有启动,但是执行不到。
描述5
历史操作我是可以跑起来vscode debug的,这次怎么不行了。
描述6
{
    // 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": "launch",
            "name": "Egg Debug",
            "runtimeExecutable": "npm",
            "runtimeArgs": [
                "run",
                "debug",
                "--",
                "--inspect-brk"
            ],
            "console": "integratedTerminal",
            "restart": true,
            "protocol": "auto",
            "port": 9229,
            "autoAttachChildProcesses": true
        },
        {
            "type": "node",
            "request": "launch",
            "name": "Egg Test",
            "runtimeExecutable": "npm",
            "runtimeArgs": [
                "run",
                "test-local",
                "--",
                "--inspect-brk"
            ],
            "protocol": "auto",
            "port": 9229,
            "autoAttachChildProcesses": true
        },
        {
            "type": "node",
            "request": "attach",
            "name": "Egg Attach to remote",
            "localRoot": "${workspaceRoot}",
            "remoteRoot": "/usr/src/app",
            "address": "localhost",
            "protocol": "auto",
            "port": 9999
        }
    ]
}

回答

0

在我神奇操作下,webstorm爸爸满血复活。vscode暂时不处理了。

5

@atian25 借楼提个建议: 使用 egg service 快捷生成样板代码的命名有问题,我看egg_cnode项目里都是帕斯卡命名。

6

@luckymore 自己写 snippet 吧,vscode-eggjs 这个扩展是我写着玩的,现在 vscode 新版本有问题

4

@chengnuo 新版本的vscode依然有时候需要这样操作,Mac下Fn呼出F1,选择F1,debug 添加两个进程到Node进程,一个是5800端口,一个是非9229端口

6

@chengnuo 新版本的vscode依然有时候需要这样操作,Mac下Fn呼出F1,选择F1,debug 添加两个进程到Node进程,一个是5800端口,一个是非9229端口

求更多关于这个的资料,有时真被这个弄得一头雾水,这个难道每次都要手动添加?

0

我还时常需要手动杀 5800 和 9229 端口的进程

6

一个 node debug 有那么难么。。。

2
"configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Egg Debug",
            "runtimeExecutable": "npm",
            "runtimeArgs": [
                "run",
                "debug",
                "--",
                "--inspect-brk"
            ],
            "console": "integratedTerminal",
            "restart": true,
            "protocol": "auto",
            "port": 9229,
            "autoAttachChildProcesses": true
        }
  ]

建议认真看下这个 vscode 配置里面的每一个单词。 就是一个非常简单的声明而已。

autoAttachChildProcesses 就是告诉 vscode,主进程(master) 的所有子进程都自动 attach 掉。

如果有问题,说明你上一个调试进程被成功终止连接,vscode 的使用问题。

或者把这个设置为 false,然后配置 vscode 的 autoattach 为 on,即告诉 vscode 不管什么子进程,只要是这个 vscode 里面启动的所有 node 都无脑 attach 掉。

6

我猜测是 VSCode 现在 autoAttachChildProcesses 字段有 bug 没有生效,但暂时未有证据