-
Notifications
You must be signed in to change notification settings - Fork 385
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Any way to debug functions? #409
Comments
this is interesting bc nobody’s asked for this before but it seems so natural. guess we’re all used to console.log debugging 😂 Raes is probably better at answering the —inspect flag but in general netlify dev is meant to make functions super easy to debug. its not much different from running a node server locally with env variables injected from your build settings. perhaps if you gave more insight into your problem we can suggest debugging steps |
Not sure if this is what @fineline needs, but for me, being able to attach a local instance of the chrome debugger so that I can step through a lambda function is in orders of magnitude more helpful than just |
what do we need to do on our end to make that happen? never done this before. i guess node doesnt just do this by default? 😂 |
I haven't looked at how
All that's really needed to make this work is to pass the If the above works, all that @sw-yx and the team would really need to do is provide their own flag (eg, |
@8eecf0d2 I tried Edit: Actually, I can see that Chrome debugger is able to attach to localhost:34567 (the lambda server) with |
I have some more progress. I'm able to hit breakpoints in the built js files in Webstorm and Chrome Debugger. Note that the debugger has to point to port 9229 and not the port the lambdas are served from. https://nodejs.org/de/docs/guides/debugging-getting-started/. I think the next step is to figure out how to generate source-maps with netlify-lambda so I can hit ts breakpoints. |
|
Okay I got it working with TypeScript. For anyone wondering:
in the webpack.config.dev.js
run |
@sudall just doing |
Any updates on this? |
Looks like |
Just an update to this, today I discovered the NODE_OPTIONS=--inspect netlify dev I think this is a much nicer experience, so nice in fact that if this was added to the docs I think this issue could be closed. |
Worked for me in Nuxt.js project on Mac OS:
|
That didn't work for me, it returned:
Even though no other node instance is running |
You can do this in VS Code by adding a launch file. In order for VS Code to attach a debugger, the program that is executed must be relative to the local workspace, so first install npm install netlify-cli --save-dev Then you can add the following {
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}\\node_modules\\.bin\\netlify",
"args": ["dev"]
}
]
} Other Threads: |
I got it working in VS Code using the following: package.json
launch.json {
"version": "0.2.0",
"configurations": [
{
"name": "Launch Node",
"type": "pwa-node",
"request": "launch",
"runtimeArgs": ["run-script", "debug"],
"runtimeExecutable": "npm",
"skipFiles": ["<node_internals>/**"]
}
]
} Using netlify-cli@2.65.6 |
I found this: https://daily.dev/blog/how-to-debug-netlify-serverless-lambda-functions-using-vs-code Works perfect, I see similar answers on this one. Hope this helps |
By entire For this full stack debug, I assume |
Yes, and I believe it should be |
Might there be another flag coming that ignores
Is it just semantics, or is there a technical difference as well? Thanks for the reply, erez. |
With VSCode you can use https://code.visualstudio.com/docs/nodejs/nodejs-debugging#_additional-configuration
I wasn't able to get |
Indeed only However, it doesn't respect any breakpoints set in VS code. Could you take a look? I set up a minimal reproducible repo (netlify dev/functions/nuxt/typegrapql) and I'm happy to provide it as an example guide once it can properly integrate. |
Trying to get this working for 2 days now ... really frustrating ... |
Hi @MentalGear, for VSCode you can follow #409 (comment) |
Hi @erezrokah I tried this comment for VS code. Also I tried #409 (comment) but I do not see I want this debug point in vs code - any help is appreciated. |
Hi @kgpingle, have you installed the CLI locally by running |
Fullstack
|
Thanks @erezrokah & @MentalGear - Sorry for late reply. Because I see below o/p for FullStack Debug
|
Same here, breakpoints not working for me. |
For anyone still experiencing issues with debugging functions in VS Code, can you try to follow the steps in https://cli.netlify.com/vscode/? If that doesn't work, please add a comment here and we'll reopen the issue. Thanks! |
Thanks for merging @eduardoboucas |
@eduardoboucas still struggling for yarn workspaces. I see below in console. However my server (toml file) is under
|
Has anyone successfully gotten breakpoints to work in vscode when using esbuild as the bundler? esbuild is creating the source map but breakpoints are not working for me. If I set the breakpoints on the transformed file, it works fine. But I want to be able to set them on the original file. |
I tried that exact config and it did not work for me. I got this error:
I had to go back to the config I used with netlify-lambda:
I'm having the problem I mentioned in the above post though. |
For whoever else has this issue, the launch config in the Netlify documentation (https://cli.netlify.com/vscode/) mostly worked for me. I just had to change:
to:
I suspect the issue is when you don't have netlify-cli installed globally (I only install locally per project). Hope that helps! |
If it's helpful to anyone I
Confirm this works for me. Thanks to this thread and everyone here. Here's my |
Not a bug or feature request but an enquiry:
What context do javascript lambda functions run in when using netlify dev? Is there any way to pass the --inspect flag so a debugger can be connected like a standard node app?
Thanks, and great work on netlify dev.
The text was updated successfully, but these errors were encountered: