Debug CoffeeScript sources with node-inspector

752 views Asked by At

I'm using CoffeeScript for a while to write Node.js programs. It's ok to debug with node-inspector if I compile the sources with Source Maps.

However, when I try to create a mixed Javascript/CoffeeScript app by using coffee-script/register:

#!/usr/bin/env node
require('coffee-script/register');
require('../src/client');

Then, node-inspector shows the compiled Javascript.

Is there how to see the actual *.coffee sources in node-inspector when I'm not explicity compiling it?

1

There are 1 answers

0
Miroslav Bajtoš On BEST ANSWER

Disclaimer: I am a maintainer of Node Inspector

In order to see the actual *.coffee file in Node Inspector, you need to provide a source-map file describing how to map the transpiled javascript loaded inside Node/V8 runtime to you coffee-script source. Additionally, the filename of the transpiled javascript must be different from the original script name (AFAIK).

This is the trouble with require('coffee-script/register'): it converts the coffee-script source to the javascript source while keeping the same file name. In other words, the runtime (and Node Inspector) see that your *.coffee contain the transpiled javascript, thus it cannot display your coffee script for that very same filename. Also AFAIK, the coffee compiler does not emit any source map in this case.

I see two possible approaches to fix the problem:

  1. Modify loadFile() in coffee-script/register:

    • emit a source map and save it to a file
    • pass a different filename to module._compile, e.g. script.coffee.js
  2. Modify coffee-script/register to emit an embedded source map. Fix Chrome DevTools and/or Node Inspector to support embedded source maps.

References: