Debugging node apps using node-inspector is pretty simple if you're scripting using JavaScript or compiled Coffee (coffee -c -m script.coffee
).
However, when using the coffeescript require
handler:
require('coffee-script/register');
require('lib/component.coffee');
in a script I'm trying to debug using node-debug
, I get:
(function (exports, require, module, __filename, __dirname) { #
^
SyntaxError: Unexpected token ILLEGAL
at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
...
right as I require
the file.
Is what I'm trying to do possible? I have several CoffeeScript files that I would much rather not have to compile each time I want to test.
Yes, definitely. I use it all the time, the command line looks like these:
node-inspector & coffee --nodejs --debug-brk ./scripts/mongoEtl.coffee
node-inspector & mocha --compilers coffee:coffee-script ./test/dataLayer-test.coffee --ui bdd --debug-brk
node-inspector --web-port=5870 & mocha --compilers coffee:coffee-script/register ./test/dataLayer-test.coffee --ui bdd --debug-brk=5880 -g 'my test name here'
I just checked the last line, it's working and has coffeescript requires in it. However when I'm debugging I'm actually seeing javascript, not coffee. I don't know if it's possible to run and debug coffeescript with node-inspector (edit: yes, it is, use of source maps is required but that is out of scope for this answer). I'm not convinced that has value -- I think it's good to be able to read javascript well, so I haven't looked into it.
I think your issue might be in the compilation, have you tried compiling the file that's being required?