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

Unable to debug (in Webstorm) with ts-babel-node #18

Open
dan-j opened this issue Jul 21, 2017 · 2 comments
Open

Unable to debug (in Webstorm) with ts-babel-node #18

dan-j opened this issue Jul 21, 2017 · 2 comments

Comments

@dan-j
Copy link

dan-j commented Jul 21, 2017

If I run ts-node I am able to use the Webstorm debugger however with ts-babel-node I'm not.

I'm not sure what the issue is other than it's when registerBabel() is called. I thought it may have been an issue with how source-maps are configured but I've tried commenting the overrideSourceMaps() function but that doesn't help.

In webstorm, I get the following output for ts-babel-node:

/Users/Dan/.nvm/versions/node/v8.2.0/bin/node /Users/Dan/.nvm/versions/node/v8.2.0/lib/node_modules/npm/bin/npm-cli.js run ts-babel-node --scripts-prepend-node-path=auto

> [email protected] ts-babel-node /Users/Dan/Documents/git_repos/ts-babel-node-debugger-issue
> ts-babel-node $NODE_DEBUG_OPTION index.ts

parent directory of here is: /Users/Dan/Documents/git_repos

Process finished with exit code 0

For ts-node, where the debugger works:

/Users/Dan/.nvm/versions/node/v8.2.0/bin/node /Users/Dan/.nvm/versions/node/v8.2.0/lib/node_modules/npm/bin/npm-cli.js run ts-node --scripts-prepend-node-path=auto

> [email protected] ts-node /Users/Dan/Documents/git_repos/ts-babel-node-debugger-issue
> ts-node $NODE_DEBUG_OPTION index.ts

Debugger listening on ws://127.0.0.1:54769/aa160606-b3ee-4c63-9972-9fab24593856
For help see https://nodejs.org/en/docs/inspector
Debugger attached.
parent directory of here is: /Users/Dan/Documents/git_repos
Waiting for the debugger to disconnect...
Debugger listening on ws://127.0.0.1:54769/aa160606-b3ee-4c63-9972-9fab24593856
For help see https://nodejs.org/en/docs/inspector

Process finished with exit code 0

I've created a repo with details to reproduce, https://github.com/dan-j/ts-babel-node-debugger-issue. Note I'm using a forked version of ts-babel-node (which has a pull request open at the moment #16) but I've confirmed the debugger doesn't work in version 1.1.0 either (just 1.1.0 doesn't work with [email protected] and [email protected])

I've also tried with node v7.10.1, to no avail.

@dan-j
Copy link
Author

dan-j commented Jul 21, 2017

I've found the problem!

Essentially source maps must be emitted inline for WebStorm to pick it up and act on breakpoints accordingly. Attaching them as comments made everything work, however this only solved the problem when using the require hook (node -r ts-babel-node/register ...) or using require('ts-babel-node/register).

In order to also have this working using the ts-babel-node executable, it needs to require ts-node/dist/bin, not ts-node/dist/_bin.

#! /usr/bin/env node
'use strict';

require('..').registerBabel();
< require('ts-node/dist/_bin');
---
> require('ts-node/dist/bin');

I think (I've only quickly looked into why) this is because bin.js spawns a new process with the correct node arguments, i.e.

node [nodeArgs] _bin.js [tsNodeArgs] [script] [scriptArgs]

Whereas for _bin.js all arguments are treated as ts-node arguments, i.e.

node _bin.js [nonScriptArgs] [script] [scriptArgs]

By using _bin any node arguments, for instance --debug, --inspect etc., are passed as arguments to bin.js so the node process can't attach the debugger.

I've not had much response from issues I've raised here (although I've been full-on for the past 2-3 days and appreciate you also may be busy), so I'm going to continue with my forked version for now. I'll try and write some tests and create a proper PR, I'll make a point of doing it sooner rather than later if I get a response

@dan-j
Copy link
Author

dan-j commented Jul 21, 2017

Ignore half of that last comment. You can't use bin.js because it spawns a new process which means this module hasn't registered the .ts or .tsx hooks to require.extensions[]. I thought it worked because my code didn't actually require babel so it looked like it worked, but it wasn't actually using this module 😞

There may just have to be a limitation that for debugging, you must use node's -r hook or call require('ts-babel-node/register) yourself.

dan-j pushed a commit to dan-j/ts-babel-node that referenced this issue Jul 22, 2017
- Removed inputSourceMap from babel and use merge-source-map to join TS
and Babel maps
- Accept TS source maps from either file comment or inline
- Attach inline source maps to compile code to support debugging
dan-j pushed a commit to dan-j/ts-babel-node that referenced this issue Jul 22, 2017
- Removed inputSourceMap from babel and use merge-source-map to join TS
and Babel maps
- Accept TS source maps from either file comment or inline
- Attach inline source maps to compile code to support debugging
dan-j pushed a commit to dan-j/ts-babel-node that referenced this issue Jul 22, 2017
- Removed inputSourceMap from babel and use merge-source-map to join TS
and Babel maps
- Attach inline source maps to compile code to support debugging
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

1 participant