KevinResoL KevinResoL - 4 months ago 41
Node.js Question

Haxe/Nodejs debugging - Source mapping

How to enable source mapping on nodejs? I wish to have the stack trace to map on the .hx files instead of the generated .js file.



class Main
public static function main()
throw "test";


-lib hxnodejs
-cp src
-js bin/index.js
-main Main

output: (
cd bin && node index.js

throw new js__$Boot_HaxeError("test");
Error: test
at Function.Main.main (/Users/kevin/Codes/testnodejs/bin/index.js:10:8)
at console.undefined.log (/Users/kevin/Codes/testnodejs/bin/index.js:21:6)
at Object. (/Users/kevin/Codes/testnodejs/bin/index.js:22:3)
at Module._compile (module.js:434:26)
at Object.Module._extensions..js (module.js:452:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:475:10)
at startup (node.js:117:18)
at node.js:951:3

  1. Install "source-map-support" from npm

    npm install source-map-support
  2. Enable -debug in your hxml (so that Haxe generates the source map file)

  3. Run install() in the very beginning of your program:

  4. Assign the wrapCallSite function to haxe.CallStack

    haxe.CallStack.wrapCallSite = js.Lib.require('source-map-support').wrapCallSite;