In my case, I want to debug CoffeeScript, but this question is NOT CoffeeScript specific. It relates to debugging ANY non-JavaScript language that compiles to JavaScript. To do that, you need to create a sourcemap, which nodejs is capable of. But then, I want to see and step through and inspect variables in my CoffeeScript code, knowing that nodejs will actually be executing the corresponding JavaScript code - mapping the line numbers between them by using the sourcemap. Someone will, no doubt, ask for my source code, so let's just use this (call it temp.coffee):
orders = [341, 454, 198, 264, 307]
totalOrders = 0
debugger
for order in orders
totalOrders += order
console.log totalOrders
Note that I added a 'debugger' statement, though that should not be necessary - by default, nodejs should stop just before executing the first statement. I've actually come close to achieving my goal by doing this in my terminal:
coffee -cm temp.coffee
node inspect temp.coffee
The first statement compiles temp.coffee into temp.js, also producing file temp.js.map - a sourcemap file. The second statement also appears to work - it tells me that the debugger is attached and gives me a prompt. Unfortunately, if I try to execute the 's' command to step over the next statement in my program, it tells me "Uncaught Error [ERR_DEBUGGER_ERROR]: Can only perform operation while paused." Why is it not paused??? I've tried using the 'run' or 'restart' commands, but I get the same result. I'm hoping that I'm just forgetting to do something and that someone can clue me in.
from nodejs debugging with non-javascript
No comments:
Post a Comment