I've been trying to debug my Next.js app using VS Code, but the debugger isn't hitting the breakpoints, even though I've configured everything correctly (I think!). Here's what I've done so far:
I run the app using:
npm run debug
This corresponds to the following script in my package.json:
"scripts": {
"debug": "cross-env NODE_OPTIONS='--inspect' next dev"
}
I set breakpoints in my code, then reload the page in the browser to hit the breakpoints.
I press F5 in VS Code to start the debugger. My launch.json file is attached as a screenshot below.
My tsconfig.json has sourceMap: true set up correctly for source maps.
Despite following these steps, the breakpoints are not getting hit, and the debugger doesn’t pause execution at the expected lines. When I run a simpler JavaScript file, everything works fine. The issue only seems to happen with my Next.js app.
launch.json:{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Attach to Next.js",
"skipFiles": ["<node_internals>/**"],
"port": 9229
}
]
}
npm run debug as described.npm run build -- --no-cache.sourceMap: true in my tsconfig.json and Next.js config.Has anyone else run into this issue? What could I be missing in the setup to ensure the debugger hits the breakpoints in a Next.js app?
What helped me:
I managed to solve the issue by switching to WebStorm. The Next.js debug configuration works well there, and breakpoints are successfully hit.
However, I’m still looking for a solution to get this working in VS Code. Here’s what I’ve tried so far that didn’t work:
launch.json instead of the Node.js configuration, but the breakpoints still don’t get hit.The question remains open for how to get breakpoints working correctly in VS Code for Next.js. Any insights would be appreciated!
I've had similar issues working with Turbopack.
You can refer to the basic guidelines at https://nextjs.org/docs/app/guides/debugging for more information.
Focus on the part "If you're running Next.js from a directory other than root (for example, if you're using Turborepo) then you need to add cwd to the server-side and full stack debugging tasks. For example, "cwd": "${workspaceFolder}/apps/web"."
I still had issues with Turbopack; it seems that as of mid-2025, it isn't so stable.
I removed the same from the package.json file:
"scripts": {
"dev": "next dev --turbopack"
}
Removing the turbopack, it looks like
"dev": "next dev"
This will make the application move to the Webpack (/default bundler), which solved it for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With