Js_of_ocaml / Lwt: Missing Ocaml threads primitives at compilation

Hello all,
I’m stuck with a js_of_ocaml compilation problem. I’ve spent a lot of time to try to understand the problem by my self but did not managed to solve it. Any help would be greatly appreciated!

Here is my problem:

It concerns some code I did not write myself. This code uses js_of_ocaml to build a GUI that interacts with a server process, which launches itself some other processes. The code used to build (and execute) finely with “thread” tag in ocamlbuild command, using js_of_ocaml and js_of_ocaml-lwt 3.0.2.
I recently had to upgrade to OCaml 4.10.0 and js_of_caml 3.5.3, and now, at compilation, “some primitives are missing”:

There are some missing primitives
Dummy implementations (raising 'Failure' exception) will be used if they are not available at runtime.
You can prevent the generation of dummy implementations with the commandline option '--disable genprim'
Missing primitives:

On the client side, here are the “lwt modules” that are used:

    1. Js_of_ocaml_lwt.Lwt_js (sleep)
    1. Js_of_ocaml_lwt.XmlHttpRequest
    1. Lwt (async, ignore_result)

Again, I would appreciate any help to understand and solve that problem.


Have you tried compiling your code (the part that is compiled to Javascript at least) without the threads tag?

Best wishes,

Dear Nicolás,
thanks for taking time to answer.

The “compilation” command, generated by ocamlbuild, that raises the problem is the following one:

 js_of_ocaml --no-runtime +js_of_ocaml-compiler/runtime.js +base/runtime.js +base/runtime.js -o client/l2w3_client.js client/l2w3_client.byte

I changed the Makefile rule to try what you were suggesting (removing the “threads” tag for the “compilation” from byte to js):

 %.js %.cma %.cmxa %.native %.byte %.docdir/index.html: $(filter-out _build/,$(wildcard */*.ml*) $(wildcard */*.html) $(wildcard */*.js) $(wildcard */*.css))
"$(OCAMLBINPATH)ocamlbuild" -use-ocamlfind -tag "thread" -plugin-tag "package(js_of_ocaml.ocamlbuild)" $(OCAMLBUILDFLAGS) $@


%.cma %.cmxa %.native %.byte %.docdir/index.html: $(filter-out _build/,$(wildcard */*.ml*) $(wildcard */*.html) $(wildcard */*.js) $(wildcard */*.css))
"$(OCAMLBINPATH)ocamlbuild" -use-ocamlfind -tag "thread" -plugin-tag "package(js_of_ocaml.ocamlbuild)" $(OCAMLBUILDFLAGS) $@

%.js: "$(OCAMLBINPATH)ocamlbuild" -use-ocamlfind -plugin-tag "package(js_of_ocaml.ocamlbuild)" $(OCAMLBUILDFLAGS) $@

Unfortunately, I still have the same error message (with the same “compilation” command).

I’m not very familiar with ocamlbuild, but I think you should try to remove the threads tag from the rule that produces the bytecode from the .ml sources, not from the rule that produces the js from bytecode.

You can look in the build log _build/_log to find out if the threads library is being linked in or not to the bytecode.

Best wishes,

indeed, I also tried to remove thread tag for %.byte objective and it did not work.
I’ll have a look at ocamlbuild log (I’m not familiar with ocamlbuild neither), and maybe I’ll just try to move to dune to see whether it changes something.
Thanks again,


Indeed, dune is much simpler for these kinds of builds, I recommend switching to it!


Update: I took time to move the compilation to dune.
Unfortunately, the result is now that there is no error at compilation time, but the problem persists: at runtime the js console outputs:

uncaught exception: 0,248,Failure,-3,caml_thread_initialize not implemented

I’ll come back to give a solution if I find one…

I’ve gotten a similar error when I was accidentally calling a library (Core, in my case) which was not supported by js_of_ocaml.