0

I'm trying to export a standalone library in JavaScript thanks to js_of_ocaml. To build the JavaScript file, I used this command:

js_of_ocaml --wrap-with-fun=stringextCma --pretty --no-cmis \
-I ~/.opam/learn-ocaml/lib/stringext \
~/.opam/learn-ocaml/lib/stringext/stringext.cma \
-o stringext.cma.js

I linked the script in an index.html file. However, when I try to use the function stringextCma(window) to import it in the Firefox or Chromium console, it displays the following error:

TypeError: runtime is undefined

I don't find a way to correct it. Does someone else have this error and find a way to fix this ?

Edit

What I'm trying to achieve is almost the same as this issue. I try to follow the same steps, including wrapping the javascript code into a function.

I want to compile some opam libraries in JavaScript and load them into the learn-ocaml toplevel as javascript files (precompile). The problem is, when I load the script, I can't load it into the toplevel because I have different errors. First, I can't use the #load_js directive because the load_script function is unknown and when I try to import the library (here stringext), I have the runtime problem....

I don't know if this is clearer...

Maiste
  • 1
  • 1

1 Answers1

0

What does standalone library mean here ? When you pass a cma file to js_of _ocaml, only the content of the cma file is compiled, not it's dependencies, not the runtime. A runtime file can be generated with "js_of_ocaml build-runtime" but it might not be what you need. Also, I don't understand why you pass wrap-with-fun and no-cmis.

To export code to JavaScript, one usually build a bytecode program and compile the whole program to JavaScript. See http://ocsigen.org/js_of_ocaml/3.6.0/manual/rev-bindings

hhugo
  • 241
  • 1
  • 3
  • Sorry, my question wasn't clear... By standalone I mean it doesn't use any extern library. I edit my post. – Maiste Jun 13 '20 at 16:01