Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

折腾了2个小时,还是没有搞定如何断点调试 egg.js #751

Closed
yandongxu opened this issue Apr 13, 2017 · 26 comments
Closed

折腾了2个小时,还是没有搞定如何断点调试 egg.js #751

yandongxu opened this issue Apr 13, 2017 · 26 comments

Comments

@yandongxu
Copy link
Contributor

试了 Webstorm 和 VS Code,看遍 Issues 也没搞定断点调试。。。
好伤啊

@atian25
Copy link
Member

atian25 commented Apr 13, 2017

。。。 webstorm 的写在文档那边了,没看到?

vscode 的用 @okalala 写的插件

@atian25
Copy link
Member

atian25 commented Apr 13, 2017

@okoala

@popomore
Copy link
Member

@yandongxu
Copy link
Contributor Author

Node: v7.9.0
Webstorm: 2016.3.4

Webstorm 的控制台输出如下:

/Users/dongxu/.nvm/versions/node/v7.9.0/bin/node /Users/dongxu/.nvm/versions/node/v7.9.0/lib/node_modules/npm/bin/npm-cli.js run debug

> [email protected] debug /Users/dongxu/Projects/egg-passport-demo
> egg-bin dev $NODE_DEBUG_OPTION

(node:76979) DeprecationWarning: node --debug is deprecated. Please use node --inspect instead.
Debugger listening on 127.0.0.1:49731
2017-04-13 22:10:15,358 INFO 76979 [master] =================== egg start =====================
2017-04-13 22:10:15,361 INFO 76979 [master] egg version 1.1.0
2017-04-13 22:10:15,362 INFO 76979 [master] start with options: {"framework":"/Users/dongxu/Projects/egg-passport-demo/node_modules/egg","baseDir":"/Users/dongxu/Projects/egg-passport-demo","port":7001,"workers":1,"plugins":null,"https":false,"key":"","cert":""}
2017-04-13 22:10:15,362 INFO 76979 [master] start with env: isProduction: false, isDebug: true, EGG_SERVER_ENV: undefined, NODE_ENV: development
2017-04-13 22:10:15,373 INFO 76979 [master] Agent Worker:76980 start with ["{\"framework\":\"/Users/dongxu/Projects/egg-passport-demo/node_modules/egg\",\"baseDir\":\"/Users/dongxu/Projects/egg-passport-demo\",\"port\":7001,\"workers\":1,\"plugins\":null,\"https\":false,\"key\":\"\",\"cert\":\"\",\"clusterPort\":49763}"]
(node:76980) DeprecationWarning: node --debug is deprecated. Please use node --inspect instead.
Debugger listening on 127.0.0.1:5856

@bugss
Copy link

bugss commented Apr 13, 2017

Webstorm 可以直接在 index.js 右键点调试. 我感觉有时候会进不了断点,关了调试重新点启动再试一次就可以了.
Webstorm 里面单元测试 设断点还不知道怎么搞. 因为会先加载.setup.js 有些变量会没有值,也不知道有谁试过没有,webstorm 里面那个单元测试 的调试还是挺好用的,点右键就能只跑某个用例.

@okoala
Copy link
Member

okoala commented Apr 13, 2017

@yandongxu
我最近写了一个插件egg-development-proxyworker,支持在vscode中断点调试,修改文件后会自动重新attach,断点位置不变。你可以先试试看,不清楚的地方可以@我

@popomore
Copy link
Member

@okoala 可以加到调试文档里去

@okoala
Copy link
Member

okoala commented Apr 13, 2017

@popomore OK

@atian25
Copy link
Member

atian25 commented Apr 14, 2017

@yandongxu 只有这么点日志?看日志是 master 启动 debug 端口是 49731, agent 也启动了,端口是 5856,然后 worker 没看到日志了。

启动脚本改为: echo $NODE_DEBUG_OPTION; egg-bin dev $NODE_DEBUG_OPTION 然后给多点日志看看

@Rwing
Copy link
Contributor

Rwing commented Apr 14, 2017

vs code market 里有一个叫 egg.js dev tools 的东西,这个应该也可以吧?

@atian25
Copy link
Member

atian25 commented Apr 14, 2017

@Rwing 两者原理不一样的,@okoala 这个插件是跟 IDE 无关的,它主要是启动了一个 socket 代理 worker 的调试 socket,这样 worker 重启后,IDE 还是连接同一个端口。

那个 vscode 扩展是 @yuzukwok#583 做的,应该可以改改用到前者的东西。

@yandongxu
Copy link
Contributor Author

@atian25

package.json

"scripts": {
    "debug": "echo $NODE_DEBUG_OPTION; egg-bin dev $NODE_DEBUG_OPTION"
}

output

/Users/dongxu/.nvm/versions/node/v7.9.0/bin/node /Users/dongxu/.nvm/versions/node/v7.9.0/lib/node_modules/npm/bin/npm-cli.js run debug

> [email protected] debug /Users/dongxu/Projects/egg-passport-demo
> echo $NODE_DEBUG_OPTION; egg-bin dev $NODE_DEBUG_OPTION

--debug-brk=51524 --expose_debug_as=v8debug
(node:2154) DeprecationWarning: node --debug is deprecated. Please use node --inspect instead.
Debugger listening on 127.0.0.1:51524
2017-04-14 11:00:40,328 INFO 2154 [master] =================== egg start =====================
2017-04-14 11:00:40,331 INFO 2154 [master] egg version 1.1.0
2017-04-14 11:00:40,331 INFO 2154 [master] start with options: {"framework":"/Users/dongxu/Projects/egg-passport-demo/node_modules/egg","baseDir":"/Users/dongxu/Projects/egg-passport-demo","port":7001,"workers":1,"plugins":null,"https":false,"key":"","cert":""}
2017-04-14 11:00:40,331 INFO 2154 [master] start with env: isProduction: false, isDebug: true, EGG_SERVER_ENV: undefined, NODE_ENV: development
2017-04-14 11:00:40,341 INFO 2154 [master] Agent Worker:2155 start with ["{\"framework\":\"/Users/dongxu/Projects/egg-passport-demo/node_modules/egg\",\"baseDir\":\"/Users/dongxu/Projects/egg-passport-demo\",\"port\":7001,\"workers\":1,\"plugins\":null,\"https\":false,\"key\":\"\",\"cert\":\"\",\"clusterPort\":51549}"]
(node:2155) DeprecationWarning: node --debug is deprecated. Please use node --inspect instead.
Debugger listening on 127.0.0.1:5856

@yandongxu
Copy link
Contributor Author

@okoala 按文档上来了一遍,报错如下:

Vs Code 调试控制台:

Debugging with legacy protocol because Node version could not be determined: Error: timeout

Terminal:

2017-04-14 11:23:54,775 INFO 5198 [master] egg started on http://127.0.0.1:7001 (992ms)
[proxyworker] tcp server listen at 10086
[proxyworker] receive new socket connection from ::ffff:127.0.0.1:59528
[proxyworker] create client socket ing...
[proxyworker] could not connect to client at host 127.0.0.1:5858
[proxyworker] client socket closed.
[proxyworker] server socket closed.
[proxyworker] receive new socket connection from ::ffff:127.0.0.1:59542
[proxyworker] create client socket ing...
[proxyworker] could not connect to client at host 127.0.0.1:5858
[proxyworker] client socket closed.
[proxyworker] server socket closed.

@atian25
Copy link
Member

atian25 commented Apr 14, 2017

WebStorm 的那个我试了下, 可以复现,还是 WebStorm 在 Node 7.x 的问题,用 Node 6.x 就可以。

@atian25
Copy link
Member

atian25 commented Apr 14, 2017

@yandongxu vscode 的那个,从你的看来是 egg 没开启 debug,贴下 egg 的启动日志。

@yandongxu
Copy link
Contributor Author

@atian25

▶ npm run dev

> [email protected] dev /Users/dongxu/Projects/egg-passport-demo
> egg-bin dev

2017-04-14 11:44:58,752 INFO 9243 [master] =================== egg start =====================
2017-04-14 11:44:58,755 INFO 9243 [master] egg version 1.1.0
2017-04-14 11:44:58,755 INFO 9243 [master] start with options: {"framework":"/Users/dongxu/Projects/egg-passport-demo/node_modules/egg","baseDir":"/Users/dongxu/Projects/egg-passport-demo","port":7001,"workers":1,"plugins":null,"https":false,"key":"","cert":""}
2017-04-14 11:44:58,755 INFO 9243 [master] start with env: isProduction: false, isDebug: false, EGG_SERVER_ENV: undefined, NODE_ENV: development
2017-04-14 11:44:58,763 INFO 9243 [master] Agent Worker:9244 start with ["{\"framework\":\"/Users/dongxu/Projects/egg-passport-demo/node_modules/egg\",\"baseDir\":\"/Users/dongxu/Projects/egg-passport-demo\",\"port\":7001,\"workers\":1,\"plugins\":null,\"https\":false,\"key\":\"\",\"cert\":\"\",\"clusterPort\":52228}"]
2017-04-14 11:44:59,138 INFO 9243 [master] Agent Worker started (379ms)
2017-04-14 11:44:59,144 INFO 9243 [master] App Worker#1:9245 start, state: none, current workers: ["1"]
2017-04-14 11:44:59,608 INFO 9245 [egg:proxyworker] Send debugPort 5858 to agent worker
2017-04-14 11:44:59,612 INFO 9244 [egg:proxyworker] ProxyPort is 10086 and debugPort is 5858
2017-04-14 11:44:59,703 WARN 9243 [master] App Worker#1:9245 started at 7001, remain 0 (564ms)
2017-04-14 11:44:59,704 INFO 9243 [master] egg started on http://127.0.0.1:7001 (949ms)
[proxyworker] tcp server listen at 10086

@atian25
Copy link
Member

atian25 commented Apr 14, 2017

你没启动 debug 啊...

image

npm run dev -- --debug 或者放到 npm scripts 里面

@yandongxu
Copy link
Contributor Author

@atian25 @okoala Vs Code 可以了!不过建议 npm run dev -- -- debug 最好加到文档里.

另外, Webstorm 有没有解决方案?

@atian25
Copy link
Member

atian25 commented Apr 14, 2017

https://eggjs.org/zh-cn/core/development.html#使用-webstorm-进行调试 这里有写的。

@okoala 看你 README 那边是不是漏了

@atian25
Copy link
Member

atian25 commented Apr 14, 2017

WebStorm 那个,要不你用 6.x,要不就是去 WebStorm 那边提 issue: debug cluster at node 7.x

@okoala
Copy link
Member

okoala commented Apr 14, 2017

@yandongxu 把启动配置也加到vscode的launch.json里是最好的了,一键启动+调试

@yandongxu
Copy link
Contributor Author

@okoala @atian25 谢谢. 这个可以关了吧?

@junmaqiang
Copy link

可以出一个支持Atom的调试文档?

@atian25
Copy link
Member

atian25 commented Jun 8, 2017

atom 啊,@fengmk2

@dead-horse
Copy link
Member

不要 at 我们,我们都是 console 调试的

@popomore
Copy link
Member

popomore commented Jun 8, 2017

不要再问调试的事情了,自己解决

@eggjs eggjs locked and limited conversation to collaborators Jun 8, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants