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

ThinkJS 3.0 断点调试 #716

Closed
guangzhoujason opened this Issue Jul 17, 2017 · 45 comments

Comments

Projects
None yet
@guangzhoujason
Copy link

guangzhoujason commented Jul 17, 2017

DESC

thinkjs3.0 beta3 用thinkjs new demo 生成的项目,在webstorm里面点击 调试 development.js 不能启动

ENV

development
Platform:
mac
Node.js Version:
8.1.4
ThinkJS Version:
3.0 beta

@songguangyu

This comment has been minimized.

Copy link
Contributor

songguangyu commented Jul 18, 2017

报了什么错误吗?是不是IDE的环境配置问题?

@guangzhoujason

This comment has been minimized.

Copy link

guangzhoujason commented Jul 18, 2017

@songguangyu 没有出现什么错误。
按webstorm的 debug development.js
控制台出现

/usr/local/bin/node --inspect-brk=57695 /Users/Jason/Documents/demo/development.js
Debugger listening on ws://127.0.0.1:57695/6df33742-9d92-4c3b-962c-cdbf095f287b
For help see https://nodejs.org/en/docs/inspector
Debugger attached.
Debugger listening on ws://127.0.0.1:57698/71f247da-3ddd-4ec5-a82b-17c558c77950
For help see https://nodejs.org/en/docs/inspector
Debugger listening on ws://127.0.0.1:57696/3b45c168-8744-4182-8f4e-93c5769e1b23
For help see https://nodejs.org/en/docs/inspector
Debugger listening on ws://127.0.0.1:57697/481d8ae5-606c-4b7b-8f5b-02d63e8bc221
For help see https://nodejs.org/en/docs/inspector
Debugger listening on ws://127.0.0.1:57699/2af0b65b-a52f-49ee-a168-2ff20a898477
For help see https://nodejs.org/en/docs/inspector

就没有任何反应了。。服务没有启动起来

同样的环境,同样的操作 我用think 2.x 是没有问题的

@guangzhoujason

This comment has been minimized.

Copy link

guangzhoujason commented Jul 18, 2017

就是很简单的 thinkjs new demo

@songguangyu

This comment has been minimized.

Copy link
Contributor

songguangyu commented Jul 18, 2017

嗯 这个是 node --inspect=27210 --debug-brk development.js 中 -brk 导致 子进程fork失败导致的,我们尽快给出解决方案

@guangzhoujason

This comment has been minimized.

Copy link

guangzhoujason commented Jul 18, 2017

ok,thanks

@songguangyu songguangyu added the bug label Jul 19, 2017

@songguangyu songguangyu added this to the v1.0 milestone Jul 19, 2017

@guangzhoujason

This comment has been minimized.

Copy link

guangzhoujason commented Jul 19, 2017

有解决这个问题的时间表吗

没有调试,麻烦啊,不断的log

@songguangyu

This comment has been minimized.

Copy link
Contributor

songguangyu commented Jul 19, 2017

争取在这周末前修复这个问题。

@guangzhoujason

This comment has been minimized.

Copy link

guangzhoujason commented Jul 19, 2017

thank you
by the way

pm2不能启动,应该也是跟这个一样的问题吧

@yaolynzc

This comment has been minimized.

Copy link

yaolynzc commented Jul 19, 2017

VS Code下面启动调试,也是报这样的错误,应该是同类问题。

@guangzhoujason

This comment has been minimized.

Copy link

guangzhoujason commented Jul 22, 2017

so,有进展吗

@songguangyu

This comment has been minimized.

Copy link
Contributor

songguangyu commented Jul 26, 2017

@guangzhoujason 在 webstrom 里 直接 debug development.js 是可以设置断点的

@guangzhoujason

This comment has been minimized.

Copy link

guangzhoujason commented Jul 27, 2017

都没有启动起来,怎么能断点
@songguangyu

都没有出来 服务器启动成功,监听什么端口的信息

官方貌似还没有给出解决方案

@songguangyu

This comment has been minimized.

Copy link
Contributor

songguangyu commented Jul 27, 2017

image

兄弟,在webstrom里 点击 Debug development.js 选项,debug 模式启动项目,然后在项目文件里,设置断点,就能进行断点调试了。 请问你这边有什么报错信息吗?

WebStorm 2017.2
Build #WS-172.3317.70, built on July 14, 2017
Licensed to WebStorm Evaluator
Expiration date: August 23, 2017
JRE: 1.8.0_152-release-915-b5 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Mac OS X 10.11.2   

这个是我的webstorm 的版本,请问你的webstorm 的版本是什么?

@guangzhoujason

This comment has been minimized.

Copy link

guangzhoujason commented Jul 29, 2017

没有报错
启动的时候就出现,类似你这样的

直接run的时候,会出现
[2017-07-29 10:58:50.509] [INFO] - Server running at http://0.0.0.0:8888
[2017-07-29 10:58:50.513] [INFO] - ThinkJS version: 3.0.0-beta3
[2017-07-29 10:58:50.513] [INFO] - Enviroment: development
[2017-07-29 10:58:50.514] [INFO] - Workers: 4
成功的消息

但是debug的时候,不会出现。。
浏览器试着访问,也访问不了

所以何来的可以断点

WebStorm 2017.2
Mac OS X 10.11.2

btw,2.x 没有问题

@junmaqiang

This comment has been minimized.

Copy link

junmaqiang commented Aug 11, 2017

成功过没有? 兄弟们,我一次都没有启动成功过!
用的是VScode, thinkjs 3.0
@yaolynzc @guangzhoujason @songguangyu

@lzy3366

This comment has been minimized.

Copy link

lzy3366 commented Aug 16, 2017

问题还是没有得到解决啊

@welefen

This comment has been minimized.

Copy link
Member

welefen commented Aug 16, 2017

@lzy3366 这块在多进程下还有问题,目前还没找到好的解决方案。

@welefen welefen removed this from the v1.0 milestone Aug 16, 2017

@guangzhoujason

This comment has been minimized.

Copy link

guangzhoujason commented Aug 17, 2017

@welefen @lizheming

今天发布的版本,也没有解决这个问题哦

@guangzhoujason

This comment has been minimized.

Copy link

guangzhoujason commented Aug 17, 2017

还是不能调试启动

@lizheming

This comment has been minimized.

Copy link
Contributor

lizheming commented Aug 20, 2017

vscode 使用 --debug-brk 启动调试会阻碍子进程监听创建,解决方法还得再找找。目前有需求的可以自行使用 node --debug 或者 node --inspect 模式启动,使用 Chrome 调试。或者用 WebStorm 也是可以的。另外 Webstorm 我也试了下,是可以启动调试的:
image

@guangzhoujason 我的版本是今天刚下的,和你的是一样的,Node 6 和 Node 8 的版本我都试过。我直接 development.js 上右键选择 debug 启动的。你是有什么其它的特殊操作么?

@jnotnull

This comment has been minimized.

Copy link

jnotnull commented Aug 22, 2017

@guangzhoujason 同样的问题,但是有时候重启下mac就好了,但是过段时间又不行了,。。。。
@lizheming 你可以换几台机器试下么,急。或者能否提供一个规避方案 不要开启多子进程。

@lzy3366

This comment has been minimized.

Copy link

lzy3366 commented Aug 22, 2017

我试了下调试, debug的是development中运行的启动服务器的代码, request进来的controller业务代码无法单步

@zhobby

This comment has been minimized.

Copy link

zhobby commented Aug 27, 2017

@guangzhoujason 你现在是使用什么方案避规?

@wurining

This comment has been minimized.

Copy link

wurining commented Aug 27, 2017

  • 这是调试开始截图

2017-08-28 4 23 16

  • 这是调试的配置,配置好后直接点击右上角的绿虫子就可以调试了。因为每次request进来新请求,都会在node的消息队列中添加新消息,所以调试过程中也可以打断点。webstorm是最新版,thinkjs是最新版。

2017-08-28 4 23 26

@guangzhoujason @songguangyu @yaolynzc @junmaqiang @lzy3366
我怀疑出现这个问题是因为Node服务被打开后未关闭,之前出现过这种情况,甚至无法启动ThinkJs。一种简单的方法,打开进程管理器(Mac中按F4调出菜单,上方搜索框输入ac,第一个就是),搜索node,然后强制退出,之后再重新调试。

@junmaqiang

This comment has been minimized.

Copy link

junmaqiang commented Aug 29, 2017

@wurining 咱们用的IDE不同

@jnotnull

This comment has been minimized.

Copy link

jnotnull commented Aug 30, 2017

@welefen 这个问题无解了么,就没有其他降级方案了么。让我们先升级上来的情何以堪啊 😢

@welefen

This comment has been minimized.

Copy link
Member

welefen commented Aug 30, 2017

@jnotnull vsc 有点麻烦,正在想办法处理。暂时可以通过打日志来调试。

@jnotnull

This comment has been minimized.

Copy link

jnotnull commented Aug 30, 2017

分享下我的webstorm下的规避步骤吧:

  1. worker设为1个

  2. 遇到下面这个提示卡在那启动不了,直接关闭webstorm,然后杀死所有node进程

Debugger listening on ws://127.0.0.1:52084/e8a07d35-5a5d-4afd-8f04-043adafc7c2d
For help see https://nodejs.org/en/docs/inspector
Debugger attached.
@zhobby

This comment has been minimized.

Copy link

zhobby commented Sep 27, 2017

@lizheming https://github.com/thinkjs/thinkjs/issues/872 我这里是使用chrome断点的,还是没有效果。是我操作步骤有问题吗?

@welefen

This comment has been minimized.

Copy link
Member

welefen commented Oct 18, 2017

VS Code 断点调试方式如下:

  • 升级 think-cluster@1.5.1
  • 修改 src/config/config.js(多模块项目为 src/common/config/config.js),添加 workers: 1 配置
  • 在项目根目录下添加文件 debug.js (与 development.js 文件同级),内容如下:
const InspectorProxy = require('inspector-proxy');
const proxy = new InspectorProxy({ port: 9999 });
const childProcess = require('child_process');

const instance = childProcess.fork('./development.js', {
  execArgv: [ '--inspect' ]
})
instance.on('message', msg => {
  if(msg.act === 'inspectPort' && msg.port) {
    proxy.start({ debugPort: msg.port });
  }
})
instance.on('exit', () => proxy.end());
  • npm install inspector-proxy 安装依赖
  • 添加 VS Code 的调试文件 .vscode/launch.json,内容如下:
{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Attach Worker",
      "type": "node",
      "request": "attach",
      "restart": true,
      "port": 9999
    }
  ]
}
  • 命令行下通过 node debug.js 启动服务,然后在 VS Code 里打开断点调试。

现在使用起来还有点麻烦,后续会将这些操作整合到脚本里。

@welefen welefen changed the title thinkjs3.0 beta3 用thinkjs new demo 生成的项目,在webstorm里面点击 调试 development.js 不能启动 ThinkJS 3.0 断点调试 Oct 18, 2017

@feng003

This comment has been minimized.

Copy link

feng003 commented Oct 21, 2017

启动 node debug.js 报错呢。thinkCluster.isAgent is not a function

@makeco

This comment has been minimized.

Copy link

makeco commented Oct 21, 2017

@feng003 升级think-cluster

@feng003

This comment has been minimized.

Copy link

feng003 commented Oct 21, 2017

@makeco 升级了 谢谢。

@feng003

This comment has been minimized.

Copy link

feng003 commented Oct 21, 2017

vscode 设置断点 但是还未绑定 是什么情况?不知道这个问题 有没有终极解决方案?

@welefen

This comment has been minimized.

Copy link
Member

welefen commented Oct 21, 2017

@feng003 是按照上面的步骤一步步来的么?

@feng003

This comment has been minimized.

Copy link

feng003 commented Oct 25, 2017

@welefen vscode 可以调试 新建的项目按照上面的步骤可以的。以前的项目 可能依赖太多了 bluebird 就报错。先学习一下 thinkjs 结构。十分感谢

@wzquyin

This comment has been minimized.

Copy link

wzquyin commented Oct 31, 2017

@welefen 你给出的方案,有些问题, proxy在获得了调试debugport后,start,但是thinkjs自己会wachter到文件变化重启所有worker,也就是说只要修改了东西,开发者就必须重启debug.js和vscode(在边调试边开发的时候非常麻烦,而且在mac上会出现需要手动lsof +kill的情况-端口占用),我在你的基础上做了修改,使用方法基本一致,但是不需要不停的重启vscode的调试和debug.js,debug.js脚本如下:

const inspector = require("inspector-proxy");
const proxy = new inspector({ port: 9999 });
const childProcess = require("child_process");
const inst = childProcess.fork("./development.js", {
execArgv: ["--inspect=9900"],
silent: true
});
var debugPort = 0;
inst.on("message", msg => {
console.info(msg);

if (msg.act === "inspectPort" && msg.port) {
  debugPort = msg.port;
    proxy.start({ debugPort: msg.port });

}

})

const str = "Debugger listening on ws://127.0.0.1:"
inst.stderr.on('data', (data) => {
console.log(${data});
if (data.indexOf(str) != -1) {
data = data.slice(data.indexOf(str) + str.length);
data = data.slice(0, data.indexOf("/"));

var port=parseInt(data)
if (isNaN(port) == false&&port>debugPort&&debugPort!=0) {
  console.log("切换端口:" + data);
  debugPort = port;
  proxy.end();
  proxy.start({
    debugPort: parseInt(data)
  });
}

}

});

写的比较简陋,但是能用,主要是增加了 silent: true来fork,然后通过监控std消息中的每次thinkjs重启了所有worker后打印出新的端口后,切换端口

使用方法还是和welefen提出的一样

@welefen

This comment has been minimized.

Copy link
Member

welefen commented Oct 31, 2017

@wzquyin 已经修复这个问题,升级 think-cluster@1.5.1,且在 debug.js 最后加上 instance.on('exit', () => proxy.end()); 代码即可。

@callmez

This comment has been minimized.

Copy link

callmez commented Nov 1, 2017

之前都可以用, 但是升级think-cluster之后 webstorm debug 报错:

[2017-11-01 16:47:02.210] [10442] [INFO] - Server running at http://127.0.0.1:8000
[2017-11-01 16:47:02.212] [10442] [INFO] - ThinkJS version: 3.2.3
[2017-11-01 16:47:02.212] [10442] [INFO] - Enviroment: development
[2017-11-01 16:47:02.212] [10442] [INFO] - Workers: 1
Debugger listening on ws://127.0.0.1:55387/ad180361-f19d-4cef-830e-76e9faaf8673
For help see https://nodejs.org/en/docs/inspector
Debugger attached.
Unhandled rejection TypeError: process.send is not a function
    at Master.sendInspectPort (/Volumes/File/go/demo/node_modules/think-cluster/lib/master.js:161:15)
    at promise.then.data (/Volumes/File/go/demo/node_modules/think-cluster/lib/master.js:170:12)
    at tryCatcher (/Volumes/File/go/demo/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/Volumes/File/go/demo/node_modules/bluebird/js/release/promise.js:502:31)
    at Promise._settlePromise (/Volumes/File/go/demo/node_modules/bluebird/js/release/promise.js:559:18)
    at Promise._settlePromise0 (/Volumes/File/go/demo/node_modules/bluebird/js/release/promise.js:604:10)
    at Promise._settlePromises (/Volumes/File/go/demo/node_modules/bluebird/js/release/promise.js:683:18)
    at Async._drainQueue (/Volumes/File/go/demo/node_modules/bluebird/js/release/async.js:138:16)
    at Async._drainQueues (/Volumes/File/go/demo/node_modules/bluebird/js/release/async.js:148:10)
    at Immediate.Async.drainQueues (/Volumes/File/go/demo/node_modules/bluebird/js/release/async.js:17:14)
    at runCallback (timers.js:781:20)
    at tryOnImmediate (timers.js:743:5)
    at processImmediate [as _immediateCallback] (timers.js:714:5)
@chj-damon

This comment has been minimized.

Copy link

chj-damon commented Nov 1, 2017

@welefen 运行node debug.js可以启动,在控制台看到有这句话:
To start debugging, open the following URL in Chrome:
chrome-devtools://devtools/remote/serve_file/@60cd6e859b9f557d2312f5bf532f6aec5f284980/inspector.html?experiments=true&v8onl
y=true&ws=localhost:9231/07642f57-0a14-4967-89af-f5003c66bf10
复制到chrome里面,可以debug,但是我在vscode里面打断点是没有用的。
同时,如果我修改了js文件,上面的这个链接会发生改变,也就意味着我需要重新复制一遍到chrome里面,新的代码才会生效。
请问有什么方式可以直接在vscode里面debug吗?

@chj-damon

This comment has been minimized.

Copy link

chj-damon commented Nov 1, 2017

升级到v8.9.0之后,控制台的这句话也没有了。vscode中打断点还是没有办法调试。

@nicholaslai

This comment has been minimized.

Copy link

nicholaslai commented Dec 1, 2017

node inspector &
node --debug development.js

Server running at http://127.0.0.1:1234
ThinkJS version: 3.2.3
Enviroment: development
Workers: 1

在chrome 中没有进入断点, 就是简单的 demo 项目

@amoxoo

This comment has been minimized.

Copy link

amoxoo commented Dec 5, 2017

关于断点的问题,困扰了我两天,今天解决了,个人提供这个场景及对应的思路。

环境:

MAC 10.12 + Webstorm v2017.3 + Thinkjs v3.2.4 + node v8.9.0

现象:

在src里打了断点,然后在WS的Run/Debug Configuration中添加了类型为Nodejs,Javascrip file为development.js的启动项(见下图1),以Ctrl+D的方式启动调试,打了断点,浏览器发请求,死活进不了断点,也把workers设为1什么一堆上面的方法都试了,都进不了断点。

(图1)
p1

分析:

  1. 了解启动配置文件的加载情况,控制台输入:

    DEBUG=think-loader-config-* npm start
    

    发现如图2所示,加载了app目录下的配置文件,猜测thinkjs内部可能是发现有编译后的文件就使用编译后的,否则就用src目录下的源码,就猜想了一下会不会代码也是如此。

    (图2)
    p2

  2. 抱着试试看的心态跑到app目录下,在转译后控制器上打了个断点,一请求居然进来了。如图3所示。

    (图3)
    p3

  3. 好吧,看源码,原来thinkjs的Application类的构造方法就在处理应用目录的问题,如图4所示。

    (图4)
    p4

  4. 如此一来,看来如果调试不需要跑转译后的代码的话,只需要在development.js加上APP_PATH的选项就可以了,如图5所示。

    (图5)
    p5

结论:

如果调试想在源码下断点,有两招:

  1. 调试前把把app目录删掉。
  2. 按以上方法在development.js加上APP_PATH。
@wangbaolongbbl

This comment has been minimized.

Copy link

wangbaolongbbl commented Jul 2, 2018

websotrm debug就报这个,进不去断点。wokers设1了
Debugger listening on ws://127.0.0.1:49373/fd9e682f-2724-429a-abf9-30a3366a3891
For help see https://nodejs.org/en/docs/inspector
Debugger attached.
(node:969) [DEP0062] DeprecationWarning: node --inspect --debug-brk is deprecated. Please use node --inspect-brk instead.

@lizheming

This comment has been minimized.

Copy link
Contributor

lizheming commented Aug 7, 2018

VSCode 1.22+ 已经原生支持多进程调试了,所以调试特别简单,只要按照如下内容配置 .vscode/launch.json 即可:

{
  "version": "0.2.0",
  "configurations": [
    {
      "port": 9229,
      "type": "node",
      "restart": true,
      "request": "launch",
      "name": "ThinkJS Debug",
      "cwd": "${workspaceRoot}",
      "runtimeExecutable": "node",
      "autoAttachChildProcesses": true,
      "runtimeArgs": ["--inspect", "development.js"]
    }
  ]
}

配置完直接 F5 启动调试就好啦~
另外也有新出的 ndb 可以非常方便的进行多进程调试,可参考文档:https://thinkjs.org/zh-cn/doc/3.0/debug.html

@lizheming lizheming closed this Aug 11, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment