koa-generator生成的koa2项目怎么在vsc中debug?
发布于 8 年前 作者 SinalVee 7168 次浏览 来自 问答

koa-generator生成了一个项目,但是在vsc中debug的时候报错 request 'launch': cannot launch program '/path/to/project/bin/run'; enabling source maps might help 然后,我把launch.json中的sourceMaps改成true,又报错 request 'launch': cannot launch program '/path/to/project/bin/run'; setting the 'outDir' attribute might help 这个outDir各种改还是报上面的错误

于是我又试着不用Launch使用Attach./node_modules/.bin/runkoa bin/www --debug运行起来之后,使用Attach debug,还是不行 request 'attach': cannot connect to runtime process (timeout after 10000ms)

请问各位大神,应该怎么办?

12 回复

@i5ting 桑大有时间解答不~

今天也在用这块调试,贴一下我的launch.json的配置 , 用Attach 是可以用的 { “name”: “Attach”, “type”: “node”, “request”: “attach”, “port”: 5858, “restart”: true }

@august-zou 能分享一下启动程序的命令吗,我试了下面这些命令然后用Attach都是超时

npm start --debug
npm run koa --debug

// npm stripts
"start": "./node_modules/.bin/nodemon bin/run",
"koa": "./node_modules/.bin/runkoa bin/www",

而且也没有Debugger listening on port 5858这句提示,netstat查看端口也没有5858

./node_modules/.bin/nodemon --debug bin/run 使用这个命令成功了 原来--debug的位置还有要求 0.0

@SinalVee 是的 但是调试断点 进去了 单步执行下去之后 会出现各种问题

@SinalVee 晚上录制视频,如果我没发出来,push我啊,年纪大了,怕忘

@i5ting 感谢桑大,期待!

先看这个吧 https://cnodejs.org/topic/572209ea35af8a704195f552 @SinalVee

runkoa在vscode里调试,还是有点问题

@i5ting 谢谢桑大!我去学习一下

两种方法: 1.在run的第一行添加 #!/usr/bin/env node

2.cp bin/run bin/run.js 或者 ln -s bin/run bin/run.js 再配置launch.json的 "program": “${workspaceRoot}/bin/run.js”, 就可以了. 但是单步执行还是有问题, 这种通过babel-register运行ES6的程序好像无解, 除非预编译成ES5代码?

回到顶部