Hello,
I’m reaching out to seek assistance with debugging Netlify edge functions locally. I have followed the documentation and various online resources, but unfortunately, I’m unable to get debugging working.
Problem:
Despite configuring the launch.json
file and using the recommended flags, the debugger doesn’t seem to connect successfully when using the netlify dev
command.
No breakpoints are hit and VS Code seems to know this because it’s showing an error message saying “Some of your breakpoints could not be set. If you’re having an issue, you can troubleshoot your launch configuration”.
Steps Taken:
- Verified
node
is up-to-date (version 21.4.0) - Created a
launch.json
file in the.vscode
folder with the configured suggested here (the one named “netlify dev” - but I also tried the “netlify functions:serve” one ) - Used the
--edge-inspect=127.0.0.1:9229
flag withnetlify dev
suggested here - Verified
netlify-cli
is globally installed and up-to-date (version 17.15.1) - Attempted running
netlify dev --edge-inspect=127.0.0.1:9229
via a separate terminal process or the launch command inlaunch.json
More info:
After fiddling around for an hour or so, I turned to ChatGPT and now my current launch.json
configuration looks like this:
{
"type": "node",
"request": "launch",
"name": "Debug Edge Functions",
"runtimeExecutable": "/Users/chris/.nvm/versions/node/v21.4.0/lib/node_modules/netlify-cli/bin/run.js", // I have Netlify installed globally and I use nvm
"runtimeArgs": ["dev", "--edge-inspect=127.0.0.1:9229"],
"port": 9229,
"restart": true,
"protocol": "inspector",
"timeout": 30000
},
This successfully runs the dev server and tells me my edge function is loaded but none of my breakpoints are being hit.
This is the loaded edge function that is running on every path.
export default async (_request, context) => {
console.log(context); // This also doesn't log anything to my terminal or debugger console.
// Get the response.
const response = await context.next();
// Get the page.
const page = await response.text();
// Return true for now (just testing).
if (true) {
response.headers.set("cache-control", "public, max-age=3600"); // Cache for 60 minutes.
// Return the unauthenticated page.
return new Response(page.replace(/<authenticated>.*<\/authenticated>/, ""), response);
} else {
response.headers.set("cache-control", "private, max-age=3600"); // Cache for 60 minutes.
// Return the authenticated page.
return new Response(page.replace(/<unauthenticated>.*<\/unauthenticated>/, ""), response);
}
};
export const config = {
path: "/*",
};
This edge function above is definitely being run because when I insert new Response("Test")
at the top of the function, “Test” shows as a blank page in my browser when I reload the page.
As an aside, the console.log(context)
line at the top of the function does not log anything to my terminal or debugger console. I have raised a separate issue for that here.
Please can you help me set up my launch.json
configuration so that I can debug my Edge functions with VSCode? Thank you for your time.