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

Debug using Devtools for Node #19

Open
MattijsE opened this issue Jun 21, 2018 · 4 comments
Open

Debug using Devtools for Node #19

MattijsE opened this issue Jun 21, 2018 · 4 comments

Comments

@MattijsE
Copy link

Is it possible to add support for debugging with the 'npm run dev' command?
I can't see to make it work using --inspect or --inspect -r ts-node/register Index.ts.

Maybe it's some issue with the combination of nodemon and ts-node.
Debugging support make it so easy to debug issues.

@fsanzv
Copy link

fsanzv commented Jul 9, 2018

Hi @MattijsE ,

I was looking for this too and just found a solution that works for me ;-)

You can do it with npm run dev:inspect adding this to your scripts section of package.json:

"dev:inspect": "cross-env NODE_ENV=DEVELOPMENT ./node_modules/.bin/nodemon --watch '**/*.ts' --exec 'node --inspect -r ts-node/register' Index.ts --ignore 'test/*.ts'",

As you can see, you must replace ts-node with node to use -r ts-node/register option.

After you run this new script, you can open chrome://inspect/#devices and click in Open dedicated DevTools for Node link to access to the DevTools where you will find your sources and you will be able to set breakpoints in files tagged with [sm] (from source map).

Best regards,
Fernando.

@camesine
Copy link
Owner

Hi @fsanzv,
If you found a solution for this, you can feel safe to send a pull request. 👍

@mandreko
Copy link
Contributor

mandreko commented Jul 10, 2018

I think this is working for me in WebStorm:

    "dev": "cross-env NODE_ENV=DEV ./node_modules/.bin/nodemon --watch '**/*.ts' --exec 'node %NODE_DEBUG_OPTION% -r ts-node/register' Index.ts --ignore 'test/*.ts'",
    "test": "cross-env NODE_ENV=TEST ./node_modules/mocha/bin/mocha --require ts-node/register --timeout 20000 test/*.ts --exit -- %NODE_DEBUG_OPTION%",

The %NODE_DEBUG_OPTION% just puts --inspect or --inspect-brk in if you select the "Debug" button instead of run, but you could easily make "dev:inspect" and "test:inspect" npm tasks as @fsanzv did above as well.

@fsanzv
Copy link

fsanzv commented Jul 10, 2018

Algo got it working in VSCode.
Create a launch.json file in your project's .vscode folder and paste this:

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "Debug Typescript Node Cluster",
      "sourceMaps": true,
      "program": "${workspaceFolder}/Index.ts",
      "outFiles": [
        "${workspaceFolder}/dist/**/*.js"
      ],
      "autoAttachChildProcesses": true,
      "preLaunchTask": "npm: build",
    }
  ]
}

Now you can debug using VSCode to set breakpoints and watch variables.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants