1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

VSCodeでnextjsのTurbopackでもデバッグする

Last updated at Posted at 2024-09-30

結論

turbopackに対応したvscodeのlaunch.jsonがまだ公式ドキュメントに用意されてないのでここに残しておきます。

launch.json
{
  "version": "0.2.0",
  "compounds": [
    {
      "name": "Debug Start All",
      "configurations": ["Launch Chrome", "Start Nextjs"],
      "stopAll": true
    }
  ],
  "configurations": [
    {
      "type": "chrome",
      "request": "launch",
      "name": "Launch Chrome",
      "url": "http://localhost:3000",
      "webRoot": "${workspaceFolder}",
      "sourceMaps": true,
      "sourceMapPathOverrides": {
        "/turbopack/[project]/*": "${webRoot}/*"
      },
      "presentation": {
        "hidden": true
      }
    },
    {
      "type": "node",
      "request": "launch",
      "name": "Start Nextjs",
      "sourceMaps": true,
      "sourceMapPathOverrides": {
        "/turbopack/[project]/*": "${webRoot}/*"
      },
      "runtimeExecutable": "npm",
      "runtimeArgs": ["run", "dev", "--", "--turbo"],
      "presentation": {
        "hidden": true
      }
    }
  ]
}

※pnpmの場合は、rutimeExecutableとruntimeArgsのワタシ型を変えるとうまくいきます

launch.json
~~ 省略 ~~ 
 "runtimeExecutable": "pnpm",
 "runtimeArgs": ["run", "dev", "--turbo"],
 ~~ 省略 ~~ 

turboモードとは

next devをたたくときのオプションで、--turboを渡すことです。
next dev --turboにするとturbopackを使って早く立ち上がってくれます。

launch.json

現在の公式ドキュメントに載っているlaunch.jsonこちら

以下抜粋

launch.json
{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Next.js: debug server-side",
      "type": "node-terminal",
      "request": "launch",
      "command": "npm run dev"
    },
    {
      "name": "Next.js: debug client-side",
      "type": "chrome",
      "request": "launch",
      "url": "http://localhost:3000"
    },
    {
      "name": "Next.js: debug full stack",
      "type": "node",
      "request": "launch",
      "program": "${workspaceFolder}/node_modules/.bin/next",
      "runtimeArgs": ["--inspect"],
      "skipFiles": ["<node_internals>/**"],
      "serverReadyAction": {
        "action": "debugWithEdge",
        "killOnServerStop": true,
        "pattern": "- Local:.+(https?://.+)",
        "uriFormat": "%s",
        "webRoot": "${workspaceFolder}"
      }
    }
  ]
}
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?