Js_of_ocaml source attribution/debugging in Dev Console?


I’m using reasonML and js_of_ocaml; it’s a large codebase and I’d really like to be able to see (at least some approximation of) the line number in the reason code where an error is thrown in the browser developer console. The current behavior is that it just attributes the error to a line in the compiled javascript.

I’ve been playing with compiler flags; combinations of {–debuginfo, --noinline, --sourcemap}. These seem to result in reasonable-looking attribution in the js source, but I’m not sure if I have to do something else to expose said attribution in the dev console?


Source maps depend on a combination of --sourcemap in the JSOO command line and compiling with the ocaml debug flag (which I believe is -g). I haven’t played with this recently but I thought Dune dev mode turned both on automatically. I guess it depends on how your project is set up.

Do other language source maps work for you? Do you have source maps turned on in your browser?


Ocaml debug flag -g seems to be enabled; output for dune printenv --profile dev . contains (ocamlc_flags (-g)) (ocamlopt_flags (-g)).

The project dune file contains:
(rule (write-file js-of-ocaml-flags-dev "(:standard --debuginfo --noinline --sourcemap)"))

And chrome devtools settings shows javascript sourcemaps as enabled. Not sure if other language source maps work, don’t do much webdev; is there a quick way for me to check?


Your settings do seem correct, yes.

For an example of source maps, try https://ryanseddon.com/demo/source_mapping/

Perhaps try the OCaml forum or OCaml discord; more experienced JSOO users there should be happy to help you figure this out!