js_of_ocaml
ocsigen.org
What it is
js_of_ocaml compiles OCaml bytecode programs into JavaScript for browsers and Node.js. It works with an existing OCaml installation and does not require libraries to be recompiled. Installation is available through opam, while Dune supports separate compilation in development and whole-program compilation in release builds. Whole-program compilation performs global dead-code elimination and cross-module optimization. The library provides a typed bridge between OCaml and JavaScript, including PPX syntax for properties, methods, constructors and objects. Browser bindings cover the DOM, Fetch, WebSockets, WebGL, workers and typed arrays. Optional packages add Lwt support, TyXML, JSON derivation and an OCaml toplevel in the browser. Documented targets include Node.js 18 or later, QuickJS-NG and modern ECMAScript 2020 browsers, including Chrome 80+, Firefox 74+, Safari 13.4+ and Edge 80+. Requirements include OCaml 4.13–5.5, Dune 3.20 or later and Menhir. The project is free and open source.
Spec sheet
- Purpose
- js_of_ocaml compiles OCaml bytecode programs to JavaScript for use in browsers and Node.js.Read 9 Oct 2026 · ocsigen.org
- Support
- The project asks users to report problems or questions through GitHub issues and include version details and a minimal reproducible example when possible.Read 9 Oct 2026 · ocsigen.org
- License
- The repository lists GPL-2.0-or-later and LGPL-2.1-or-later with the OCaml linking exception as its licenses.Read 9 Oct 2026 · github.com
- Async integration
- The optional js_of_ocaml-lwt package provides Lwt support and bindings including DOM events, XMLHttpRequest, and JavaScript promises.Read 9 Oct 2026 · ocsigen.org
- Browser APIs
- The base library includes bindings for browser APIs such as DOM, Fetch, WebSockets, WebGL, workers, and typed arrays.Read 9 Oct 2026 · ocsigen.org
- Browser bindings
- The project includes bindings for a large part of browser APIs.Read 9 Oct 2026 · ocsigen.org
- Browser support
- Generated JavaScript supports modern browsers that implement ECMAScript 2020, including Chrome 80+, Firefox 74+, Safari 13.4+, and Edge 80+.Read 9 Oct 2026 · ocsigen.org
- Build integration
- Dune supports js_of_ocaml natively and selects separate compilation in dev and whole-program compilation in release builds.Read 9 Oct 2026 · ocsigen.org
- Installation
- The compiler and related packages are installable through opam, the OCaml package manager.Read 9 Oct 2026 · ocsigen.org
- JavaScript interop
- Its library provides a typed interface for bridging differences between OCaml and JavaScript values.Read 9 Oct 2026 · ocsigen.org
- JavaScript interoperability
- The library provides a typed interface for bridging OCaml and JavaScript values, with PPX syntax for JavaScript properties, methods, constructors, and objects.Read 9 Oct 2026 · ocsigen.org
- Libraries
- The distribution includes packages for Lwt support, TyXML, JSON derivation, and running an OCaml toplevel in the browser.Read 9 Oct 2026 · ocsigen.org
- Limits
- Most of the Sys module is unsupported, extra OCaml libraries such as Thread are generally unsupported, and tail calls are not optimized in general.Read 9 Oct 2026 · ocsigen.org
- No recompiling libraries
- It works with an existing OCaml installation and does not require recompiling libraries.Read 9 Oct 2026 · ocsigen.org
- Node support
- The installation guide lists Node.js 18 or later as a supported environment.Read 9 Oct 2026 · ocsigen.org
- Optimization
- Whole-program compilation performs global dead-code elimination and cross-module optimizations to produce smaller and faster output.Read 9 Oct 2026 · ocsigen.org
- Performance
- The project says its benchmarks show generated programs typically run faster than with the OCaml bytecode interpreter.Read 9 Oct 2026 · ocsigen.org
- Requirements
- The documented compiler requirements include OCaml 4.13 to 5.5, Dune 3.20 or later, and Menhir.Read 9 Oct 2026 · ocsigen.org
- Runtime targets
- Generated JavaScript is documented to work with Node.js 18 or later, modern ES2020 browsers, and QuickJS-NG.Read 9 Oct 2026 · ocsigen.org
- Security and compliance
- The project pages reviewed do not state security certifications or compliance attestations.Read 9 Oct 2026 · ocsigen.org
- Support channel
- The contribution guide directs users to open a GitHub issue to report problems or ask questions.Read 9 Oct 2026 · ocsigen.org
- Supported OCaml libraries
- Most of the OCaml standard library is supported, while most of the Sys module is not supported and Graphics is partially supported.Read 9 Oct 2026 · github.com
Plans and prices
Strong points and limits
Strong points
- Compiles OCaml to browser and Node.js JavaScript
- Typed OCaml–JavaScript interoperability
- Bindings for major browser APIs
- Dune integration included
- Free open-source distribution
Limits
- Most of Sys is unsupported
- Thread libraries are generally unsupported
- Tail calls are not generally optimized
- Requires specified OCaml and Dune versions
Who it suits
It suits OCaml developers targeting browser or Node.js runtimes. Teams needing typed JavaScript interoperability and Dune integration can use its compiler and libraries.
Verdict
js_of_ocaml offers a documented path from OCaml bytecode to JavaScript with browser bindings and typed interop. Its runtime targets are clear, but several OCaml modules and libraries remain unsupported.
Where Specifiction places it
- Code Transpilers#5 of 288.4