21

I am trying to use node-inspector debug a nodeJS app running with babel-node.

babel-node index.js --debug

Node-inspector works but it shows the source maps in the transpiled es5 instead of es6

enter image description here

cuadraman
  • 14,964
  • 7
  • 27
  • 32

3 Answers3

5

For babel 6, I used the require hook.

Follow these instructions to get babel register. https://babeljs.io/docs/setup/#babel_register

In your app.js or entrypoint to the application add

require('babel-register')({
  sourceMaps: true
});

If you need to add other options as well, see - https://babeljs.io/docs/usage/options/#options

You should be able to use node-inspector & chrome to to debug your application

Sushant Rao
  • 474
  • 1
  • 4
  • 12
5

According to the Tao of Javascript, "Code flows in the moment, so knowledge is but a hint, like the map of a stream."

The latest version of v8 now uses a command like:

$ babel-node --inspect --debug-brk a.js

For source maps, try adding this to a.js:

import 'source-map-support/register';
Charles Merriam
  • 19,908
  • 6
  • 73
  • 83
4

It needs a wrapper that will create the source map to the source code instead of the transpiled code.

From https://babeljs.io/docs/setup/#babel_node_debug

npm install -g babel-node-debug
babel-node-debug index.js

Update

Instead of running it with babel-node I transpile it to es5 + sourcemaps and then run it with node. By doing that, node-inspector will show the proper code in the source dev tools.

I haven't figured out how to do it with babel-node

cuadraman
  • 14,964
  • 7
  • 27
  • 32
  • Recently I've been debugging using node-inspector on the compiled node app with the source maps flag on. More info here http://stackoverflow.com/questions/30773756/is-it-okay-to-use-babel-node-in-production#answer-32929589 – cuadraman Dec 23 '15 at 04:38
  • 1
    There's an unmerged pull request that fixes the problem: https://github.com/CrabDude/babel-node-debug/pull/12 – Sigfried Feb 03 '16 at 11:04