next.js 如何为NextJs和Typesctipt配置launch.json

ie3xauqp  于 2022-11-05  发布在  其他
关注(0)|答案(1)|浏览(135)

我正在尝试为以下存储库创建launch.json文件:
https://github.com/zakariamofaddel/shopify-nextjs-template
我已经尝试了默认的VS代码节点模板和NextJs launch file

VS代码默认节点生成的. vscode/launch.json文件

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Launch Program",
            "skipFiles": [
                "<node_internals>/**"
            ],
            "program": "${workspaceFolder}\\server\\index.ts"
        }
    ]
}

我能够成功运行yarn dev并使用console.log:
https://github.com/zakariamofaddel/shopify-nextjs-template/blob/38c700d8706818aa12d892b3f1193a969919e003/package.json#L9

eufgjt7s

eufgjt7s1#

在VS代码中添加TypeScript调试器扩展后,我找到了解决方案。

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Debug Localhost",
            "type": "node",
            "request": "launch",
            "args": [
                "${workspaceRoot}\\server\\server.ts"
            ],
            "runtimeArgs": [
                "-r",
                "ts-node/register/transpile-only"
            ],
            "cwd": "${workspaceRoot}",
            "protocol": "inspector",
            "internalConsoleOptions": "openOnSessionStart",
            "env": {
                "NODE_ENV": "development"
            }
        }
    ]
}

相关问题