【问题标题】:vscode launch config for next.js app用于 next.js 应用程序的 vscode 启动配置
【发布时间】:2018-02-11 13:49:33
【问题描述】:

我正在使用 Visual Studio Code (vscode) 开发一个 next.js 应用程序,我非常喜欢那个编辑器!我已经从扩展商店安装了 Debugger for Chrome。下面的配置启动了一个新的 Chrome 实例,我可以开始调试了。它在 vscode 的断点处停止,但问题来了。尽管我将它添加到“skipfiles”中,但它不显示函数的值并跳转到 node_modules 事件。 断点也不会在构造函数上停止。不支持 next.js 吗? 我经常使用异步等待语法。调试服务器端代码完美运行。

    {
        "name": "My Client",
        "type": "chrome",
        "request": "launch",
        "url": "http://localhost:3000",
        "webRoot": "${workspaceRoot}/my-client/",
        "skipFiles": [
            "node_modules/**/*.js",
            "<node_internals>/**/*.js",
            "node_modules",
            ".next"
        ]
    }

【问题讨论】:

    标签: javascript visual-studio-code next.js


    【解决方案1】:

    以下对我有用(从 Maximiliano Cespedes 的答案延伸):

    {
        // 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": "launch",
                "name": "NPM Launch",
                "runtimeExecutable": "npm",
                "cwd": "${workspaceFolder}/my-app",
                "runtimeArgs": [
                    "run-script",
                    "debug"
                ],
                "port": 9229,
                "console": "integratedTerminal"
            },
            {
                "type": "node",
                "request": "attach",
                "name": "Attach",
                "port": 9229,
                "stopOnEntry": false,
                "restart": true
            },
            {
                "type": "chrome",
                "request": "launch",
                "name": "Chrome",
                "url": "http://localhost:4200",
                "webRoot": "${workspaceRoot}"
            }
        ],
        "compounds": [{
            "name": "Debug-Full",
            "configurations": ["NPM Launch", "Attach", "Chrome"]
        }]
    }
    

    【讨论】:

    • 2 复合方法有什么好处吗?为什么要附加?
    【解决方案2】:

    我希望你的朋友还为时不晚, 这里有来自 VSCode 的解决问题的原始文档:

    {
        "version": "0.2.0",
        "configurations": [
            {
                "type": "chrome",
                "request": "launch",
                "name": "Next: Chrome",
                "url": "http://localhost:3000",
                "webRoot": "${workspaceRoot}"
            },
            {
                "type": "node",
                "request": "launch",
                "name": "Next: Node",
                "runtimeExecutable": "next",
                "runtimeArgs": [
                    "--inspect"
                ],
                "port": 9229,
                "console": "integratedTerminal"
            }
        ],
        "compounds": [
            {
                "name": "Next: Full",
                "configurations": ["Next: Node", "Next: Chrome"]
            }
        ]
    }

    【讨论】:

    • 为了让调试器运行自定义服务器,我们可以使用 "program": "${workspaceFolder}/server.js" 仍然无法调试处理 React 代码的服务器代码(例如 getDataFromTree
    • 有人发现了吗?
    猜你喜欢
    • 1970-01-01
    • 2022-07-23
    • 2022-08-06
    • 1970-01-01
    • 1970-01-01
    • 2015-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多