Netlify Dev functions - debugging and other issues

So wasn’t sure if I should put everything here or start new threads for each issue. I’m getting started with Netlify Dev and so far it’s pretty awesome. I just had a few questions/issues that I thought were worth bringing up.

First, is there a way to debug functions locally? It would be great to somehow leverage Chrome tools here. I found this related discussion on github, but so far some of the suggested solutions aren’t working for me: https://github.com/netlify/cli/issues/409.

Second, one pain point is that when running the dev server, if the function execution is stopped (i.e. errors) the dev server shuts down and we have to restart. It would be nice if we didn’t have to worry about this. On top of this, although netlify dev breaks and the functions port is closed, the other ports that are used for development remain open. I.e. when running netlify dev with my gatsby site, it opens port 34567 for functions and 8000 for the frontend. When a function breaks and I have to restart netlify dev, I get a notice that there is already a process running on port 8000 and it asks me to use another one. Maybe there is an issue with my current set up?

Hmm, so one issue is that things were breaking when I was using the callBack suggestion here: https://docs.netlify.com/functions/build-with-javascript/#format.

I stopped getting erros/breaking netlify dev when I converted to return statements as seen here: https://functions-playground.netlify.com/.

Hi @kmcaloon, can you share the function with the callback that was breaking the dev server? Could you also point out which example on this page the non-working function is based on?

Thanks for getting back. So unfortunately I don’t have the function anymore. The was the form of my function:

exports.handler = async (event, context, callback) => {
   callback( null, {
       statusCode: 200,
       body: "Hello, World"
   } );
}

Hi @kmcaloon, I think that you can’t use async in conjunction with a callback. As mentioned here, for async lambda functions, you’ll want to return an object like so:

exports.handler = async (event, context) => {
  return {
    statusCode: 200,
    body: "Hello, World"
  };
};

Hope that helps.