janestreet / bonsai

A library for building dynamic webapps, using Js_of_ocaml
MIT License
367 stars 39 forks source link

The examples do not work outside of the bonsai project #41

Closed dysinger closed 1 year ago

dysinger commented 1 year ago

Here's the simplest example:

You'll end up with errors like the following: image

dysinger commented 1 year ago

I will make a reference to #24 here but that issue is over a year old and, I think, somewhat unrelated to current problems.

Enoumy commented 1 year ago

Hello!

Does changing them to intead use bonsai.web (intead of bonsai_web) and bonsai.ppx_bonsai (intead of ppx_bonsai) make things build?

My current understanding of how dune works is that libraries have two kinds of names; a "name" and a "public_name". Libraries within the same project can refer to things by their "name", but libraries outside of the project must refer to things via their "public_name". The public name for both of these is defined within [1] and [2]

I am not fully confident this fixes the build for your case (I'd still need to reproduce this locally), but please let us know/follow up if it does/doesn't.

[1] https://github.com/janestreet/bonsai/blob/master/ppx_bonsai/src/dune [2] https://github.com/janestreet/bonsai/blob/master/web/dune

dysinger commented 1 year ago

Thanks for the tip. I made those changes and some others and got the hello world example to work in my project.

image

Notice I had to add virtual_dom to the libraries in the dune file as well. Additionally, I had to add an open statement in main.ml for the library. After doing so it complied without error.

Enoumy commented 1 year ago

As I think that your question has been answered, I will be closing this issue. Please feel free to re-open it if you have anything follow up question/want to re-open discussion. Thanks!

dysinger commented 1 year ago

I think it would be good to have clear examples that compile and work. That problem isn't solved and there isn't a ticket for it. @Enoumy

TyOverby commented 1 year ago

The examples build if you're building them out of this repository. They do not work if you copy them into your own project. This is because they have different names that you can use to reference them in dune, and you just kinda need to know this. I agree it's not great, but it's not clear what changes should be made on our end.