最近接手一个使用ThinkJs写的后台项目,但是发现这个项目在VSCode下不能够断点调试,想着后期写代码离不开断点调试,就查阅了官方配置文档,并做了一些修改。
首先,确保 VSCode 的版本 >= 1.22,
然后,添加 VS Code 的调试文件.vscode/launch.json
(点击VSCode左侧调试图标,然后点击设置按钮,选择调试node,可编辑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"]
}
]
}
最后,点击上面的调试按钮来启动服务
![b08bedaf3002b4321105d9baa3b5e3ff.png](https://i-blog.csdnimg.cn/blog_migrate/918a4fcc7f8ef591dde6c06861c0e715.jpeg)
但是,报错了!如下:
![6ceb109d899ea3632a3b8961db4d9914.png](https://i-blog.csdnimg.cn/blog_migrate/21b1497016f4d391d3dc4a6944096407.jpeg)
官方提供的launch.json是一种通用情况,具体的配置还是需要根据自己项目改动的。我的启动命令如下:
"start": "set DEBUG=think-router&&set NODE_ENV=dev&& node www/dev.js",
因此我的最终版本launch.json内容如下:
{
"version": "0.2.0",
"configurations": [
{
"port": 9229,
"type": "node",
"restart": true,
"request": "launch",
"timeout": 60000,
"name": "ThinkJS Debug",
"cwd": "${workspaceRoot}",
"runtimeExecutable": "node",
"autoAttachChildProcesses": true,
"runtimeArgs": ["--inspect", "www/dev.js"],
"env": {
"DEBUG": "think-router",
"NODE_ENV": "dev"
}
}
]
}