独书先生 Menu

Nuxt VSCODE node调试

问题

Nuxt使用时是有server端的,服务端使用node, 要想启动服务端代码的调试功能, 就需要额外配置

解决方案

在编辑器里启动调试功能,用VSCODE最佳,(使用谷歌浏览器也可以,但是比较麻烦,这里暂不研究)
 

步骤1

点击VSCODE左边栏的debug图标, 最上面点击Add Config (增加配置),这样就打开了launch.json

步骤2

写入以下代码,保存文件后即可关闭文件

 {
    // 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": "attach",
            "name": "调试nuxt",
            "processId": "${command:PickProcess}",
            "port": 9229
        }
    ]
}

步骤3

这时候debug栏目的顶部 多处一个配置了==>调试nuxt,点击即可开始调试项目,

当然,要在服务端代码(比如:server/index.js)中写 debugger 或者 自己打上断点

原文:https://appsoftea.com/zh/nuxt-vscode-node/
参考: https://www.zhihu.com/question/68652178/answer/817948318,感谢!