I'm trying to learn OCaml by way of building a website with this lovely library I found called Dream (https://aantron.github.io/dream/), but I've run into an issue when trying to work with the template preprocessor! My code
is copied straight from the 7-template example from the library's github page, and everything seems to work, up until the point I run dune build. The preprocessor, dream_eml, converts my templated code with jsx style html markup to less pretty, but more compilable, OCaml code, but when it does, it inserts a reference to the module Dream_pure, and my compiler is saying that Dream_pure is an unbound module! Below you can find the preprocessed code as well as my dune file!
dune file:
(executable
(name jenr_dev_server)
(libraries base core dream)
(preprocess (pps lwt_ppx)))
(rule
(targets jenr_dev_server.ml)
(deps jenr_dev_server.eml.ml)
(action (run dream_eml %{workspace_root}/src/server/%{deps})))
expanded code:
#1 "./src/server/jenr_dev_server.eml.ml"
let render param =
let ___eml_buffer = Buffer.create 4096 in
(Buffer.add_string ___eml_buffer "<html>\n<body>\n <h1>The URL parameter was ");
(Printf.bprintf ___eml_buffer "%s" (Dream_pure.Formats.html_escape (
#4 "./src/server/jenr_dev_server.eml.ml"
param
)));
(Buffer.add_string ___eml_buffer "!</h1>\n</body>\n</html>\n\n");
(Buffer.contents ___eml_buffer)
#8 "./src/server/jenr_dev_server.eml.ml"
let () =
Dream.run
@@ Dream.logger
@@ Dream.router [
Dream.get "/:word"
(fun request ->
Dream.param request "word"
|> render
|> Dream.html);
]
the error message
File "../../src/server/jenr_dev_server.eml.ml", line 4, characters 36-66:
Error: Unbound module Dream_pure
I tried reinstalling the library on my opam switch with opam install dream as well as reconfiguring the dune file to match the example from the library's repository
I suspect that you've disabled
implicit_transitive_depsin yourdune_projectfile. As the documentation states:Which means you'll have to add
dream-puretolibrariesin yourdunefile.It seems it could also be fixed in dream by adding
re_exporttodream-purein itslibrariesstanza.