Skip to content
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

node debugger with now dev #2864

Closed
mckernanin opened this issue Aug 24, 2019 · 21 comments
Closed

node debugger with now dev #2864

mckernanin opened this issue Aug 24, 2019 · 21 comments
Labels
area: cli triaged: feature request Issue or PR has been reviewed by a maintainer and work is being tracked

Comments

@mckernanin
Copy link

It would be fantastic to be able to connect vscode/chrome etc debugger to node apis running in now dev!

@leo leo added the triaged: feature request Issue or PR has been reviewed by a maintainer and work is being tracked label Aug 27, 2019
@leo
Copy link
Contributor

leo commented Aug 27, 2019

Can you elaborate this a bit? How would this work?

@leo leo added the area: cli label Aug 27, 2019
@mckernanin
Copy link
Author

If I run a node project without now dev, I can specify that I want to open a debugger which I can interact with. It would be great to be able to pass something to now dev that would allow me to do something similar. Example command without now dev is something like this: node --inspect -r ts-node/register ./src/index.ts

@mckernanin mckernanin changed the title [Feature Request] node debugger with now dev node debugger with now dev Aug 28, 2019
@leo
Copy link
Contributor

leo commented Aug 30, 2019

Ahh, I see. Thanks @mckernanin.

This sounds like something we could make happen at the config-level (in now.json).

@sdgandhi
Copy link

This would make the debugging workflow so much easier, really need this!

@NWRichmond
Copy link

Progress?

I got so far as to get the VSCode debugging tools to launch now dev, with lambdas working as expected, with the following launch.json:

{
  // Use IntelliSense to learn about possible attributes.
  // Hover to view descriptions of existing attributes.
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "Launch Now Dev",
      "program": "/home/nick/.yarn/bin/now",
      "args": ["dev"]
    }
  ]
}

To set up on your machine, replace /home/nick/.yarn/bin/now with the location of your globally-installed now executable.

At least 2 problems remain:

  1. What I can't figure out (probably because of my lack of experience with debugging using VSCode) is how to actually get the debugging features to work. As in, set breakpoints in the lambdas accessible through the routes defined in my now.json, and have those breakpoints get caught when running those lambdas through now dev.

  2. Just going by the error codes that I'm getting, it looks like there might be an issue with source maps, causing an exception, albeit one which doesn't prevent the development server from running. Here's the Debug Console output from VSCode:

/home/nick/.nvm/versions/node/v12.8.0/bin/node --inspect-brk=19993 ../../../../.yarn/bin/now dev 
Debugger listening on ws://127.0.0.1:19993/40ef08d3-4140-43e0-8d7a-b6d7a04d04a7
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
SourceMaps.getMapForGeneratedPath: exception while processing path: /home/nick/.config/yarn/global/node_modules/now/dist/index.js, sourcemap: index.js.map
TypeError: Cannot create property 'sourceRoot' on string '{"version":3,"sources":["/webpack/bootstrap","../.ent/node_modules/async-sema/lib/index.js","../home/runner/work/now/now/node_modules/generic-pool/lib/Pool.js","../home/runner/work/now/now/node_modules/@zeit/fun/node_modules/tar/lib/update.js","../node_modules/node-fetch/lib/request.js","../home/runner/work/now/now/node_modules/@sentry/node/dist/version.js","../home/runner/work/now/now/node_modules/inquirer/node_modules/ansi-regex/index.js","../home/runner/work/now/now/node_modules/asynckit/serialOrdered.js","../external \"domain\"","../home/runner/work/now/now/node_modules/source-map-resolve/lib/resolve-url.js","../home/runner/work/now/now/node_modules/stripe/lib/stripe.js","../home/runner/work/now/now/node_modules/bluebird/js/release/each.js","../src/util/output/elapsed.ts","../home/runner/work/now/now/node_modules/psl/index.js","../home/runner/work/now/now/node_modules/stream-to-promise/node_modules/once/once.js","../home/runner/work/now/now/node_modules/download/node_modules/content-disposition/index.js","../home/runner/work/now/now/node_modules/ecc-jsbn/index.js","../home/runner/work/now/now/node_modules/sshpk/lib/key.js","../home/runner/work/now/now/node_modules/@sentry/utils/dist/logger.js","../home/runner/work/now/now/node_modules/minipass/index.js","../home/[...]

> Now CLI 16.3.1 dev (beta) — https://zeit.co/feedback/dev
> Ready! Available at http://localhost:3000

System and Versions

Linux x64 (Pop_OS! 19.10)
Now 16.3.1
Visual Studio Code 1.39.2

@mckernanin
Copy link
Author

Now dev would need to expose access to the debugger enabled node process.

Sent with GitHawk

@sdgandhi
Copy link

sdgandhi commented Oct 29, 2019

Sorry @NWRichmond, we can't debug a program launched by another process (now). It is possible if now dev adds a flag to set debug and port options.

@Vadorequest
Copy link

This is important, I'm looking at a way of doing this when running my Next.js app from my local computer.

@Vadorequest
Copy link

Found a hacky way that is documented on #2077

And this issue should be closed in favour of the other one

@chabou
Copy link
Contributor

chabou commented Dec 4, 2019

It could be better to add some mechanism to add any flag to underlying node instance --inspect or any other flag with now-cli.

@leo I don't think that now.json is the right place because you probably want to activate it only through a yarn/npm command like yarn dev:inspect.
The main reason why you don't want to have this inspect mode always activated (with your config file), is because it can conflict with the default listening port, if you have another node process with inspection enabled. If we choose this config file way to activate it then we need to let user choose a port number.

It would be easier to only add a --inspect option to now-cli but I don't think it would be relevant for other platform than node.

I would happy to help because I am migrating my API from now v1 to v2 and loosing this debug capability is a real blocker.

@neoromantic
Copy link

Desperately want this!

@leo
Copy link
Contributor

leo commented Dec 27, 2019

Thank you for creating this issue!

Please note that – in order for us to be able to handle each feature request with care – we have to consume all of them through a unified pipeline that makes it easier for us to prioritize, track and progress on the features our user base is interested in.

In turn, the Issues tab on this repository is best only be used for reporting bugs, which we can immediately act on.

For well-explained feature requests (like the one you just posted), please contact us at support@zeit.co, so that we can consider adding it to our roadmap.

@leo leo closed this as completed Dec 27, 2019
@Vadorequest
Copy link

As asked, I wrote to the support team and will update this thread if anything new comes up. (even though it's closed)

@dohomi
Copy link

dohomi commented Jan 20, 2020

@Vadorequest are there any news about this issue? I'd like to use webstorm debugger but haven't found a way yet

@Vadorequest
Copy link

I haven't had any feedback from the support team at this time.

@gaoxiaoliangz
Copy link

gaoxiaoliangz commented Feb 9, 2020

install now locally and then

node --inspect node_modules/.bin/now dev

but the break point doesn't work, vscode says: "Breakpoint ignored because generated code not found (source map problem?)"

@dohomi
Copy link

dohomi commented Feb 10, 2020

@gaoxiaoliangz this is the exact issue found with Webstorm debugger. I can start the debugger or run the code but the breakpoints doesn't work at all.

@rickstaa
Copy link

rickstaa commented Nov 8, 2021

I currently use the following steps to debug my code on the local vercel instance using vscode:

  1. Start the local vercel server using vercel dev.
  2. Go to the vscode debug tab ctrl + shift + d.
  3. Create a launch.json file using the create a launch.json file button.
  4. Chose node.js option from the dropdown menu.
  5. Add another configuration using the Add Configuration button.
  6. Choose node.js: Attach to process option from the dropdown menu.
  7. Set a breakpoint.
  8. Start the Attach by Process ID debug session.
  9. See that the debugger works.

Hope this helps somebody.

@offero
Copy link
Contributor

offero commented Nov 19, 2021

Still struggling with trying to get the vscode debugger to work on a next app with vercel dev.. This is such a disjointed experience. I cannot set a breakpoint in vscode.

@rickstaa
Copy link

rickstaa commented Nov 22, 2021

@offero Strange, I have the breakpoints working on my side (see system info below) . I however noticed that on firefox sometimes the breakpoints are skipped. Did you try chrome?

Version: 1.62.3
Commit: ccbaa2d27e38e5afa3e5c21c1c7bef4657064247
Date: 2021-11-17T08:00:36.721Z
Electron: 13.5.2
Chrome: 91.0.4472.164
Node.js: 14.16.0
V8: 9.1.269.39-electron.0
OS: Linux x64 5.11.0-38-generic

@huantbui
Copy link

I got vscode to debug with vercel dev.

In your package.json, create any script name (eg: "start:local": "vercel dev").
Click on a break point that you want your code to stop at a specific API route.
Hover over the "start:local" and run as: "Debug Script". Call that API route and it should hit that endpoint with your data.

vscode-vercel-dev

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: cli triaged: feature request Issue or PR has been reviewed by a maintainer and work is being tracked
Projects
None yet
Development

No branches or pull requests