This page documents the command-line options for the js_of_ocaml compiler. Most of these options also apply to wasm_of_ocaml. Differences are noted where applicable.
Option | Description |
| Display the compiler version |
| Set output filename |
| Set optimization profile (default: 1). See Optimizations |
| Enable option. See Enable/Disable options |
| Disable option. See Enable/Disable options |
| Add directory to the list of include directories |
Option | Description |
| Pretty print JavaScript output, preserve OCaml variable names |
| Disable code inlining |
| Output debug information (source locations) |
| Generate source map. See Source maps |
Option | Description |
| Build for target environment (default: |
Possible values:
isomorphic - Runs in both browser and Node.js (default)browser - Browser-specific, smaller outputnodejs - Node.js-specific, smaller outputOption | Description |
| Select effect handler implementation |
For js_of_ocaml (default: disabled):
disabled - No effect handler support (default)cps - CPS transformation for effect supportdouble-translation - Keep both direct and CPS versions; choose at runtimeFor wasm_of_ocaml (default: jspi):
jspi - JavaScript-Promise Integration (default). Available in Chrome 137, Node.js 25, and higher. Use cps for other browsers. Performing effects is slower than with cps.cps - CPS transformation for effect supportnative - WebAssembly stack switching (wasm_of_ocaml only). Available, behind the --experimental-wasm-wasmfx flag, in Chrome 148 or higher, or in a recent Node.js canary release (V8 version 14.7.100 or higher).disabled - No effect handler supportSee Effect handlers for details.
Option | Description |
| Generate source map (separate file) |
| Don't generate source map |
| Inline source map in the JavaScript output |
| Don't embed source code in source map |
| Set root directory for source map paths |
Js_of_ocaml provides a pseudo filesystem for programs that read files at runtime. The --file flag is also supported by wasm_of_ocaml.
Option | Description |
| Register file to pseudo filesystem (default target: |
| Write filesystem data to separate file (js_of_ocaml only) |
| Allow registering files from outside at runtime (default, js_of_ocaml only) |
| Only allow files embedded at compile time (js_of_ocaml only) |
Option | Description |
| Set environment variable at compile time |
When OCaml code calls Sys.getenv, js_of_ocaml resolves variables in this order:
--setenv VAR=value, return itprocess.envglobalThis.jsoo_env (useful for setting variables in browsers)Not_found// Set environment variables before loading the OCaml program
globalThis.jsoo_env = {
DEBUG: "true",
API_URL: "https://api.example.com"
};Option | Description |
| Compile an OCaml toplevel (embeds necessary .cmi files) |
| Don't include .cmi files in toplevel |
| Enable dynamic linking of bytecode |
| File listing units to export for toplevel/dynlink |
| Link all compilation units and primitives |
See Building a toplevel for details.
Option | Description |
| Don't include the standard runtime |
| Include partial runtime when compiling .cmo/.cma |
| Preserve unit names (for separate compilation) |
| Wrap output in a function (default: IIFE) |
| Add custom header (e.g., |
See Compilation modes for details.
Use --opt <level> to select a profile:
--opt 1 - Basic optimizations (default)--opt 2 - Standard optimizations--opt 3 - Maximum optimizations (iterates until fix-point)For debugging:
js_of_ocaml --pretty --no-inline program.byte
For production:
js_of_ocaml --opt 3 program.byte
Use --enable <opt> or --disable <opt> to control these flags:
Option | Default | Description |
| false | Pretty print JavaScript output |
| true | Use short variable names |
| true | Generate "use strict" |
| true | Include compiler version header |
| false | Generate ES6 syntax |
Option | Default | Description |
| true | Dead code elimination |
| true | Global dead code elimination |
| true | Function inlining |
| true | Static evaluation of constants |
| true | Share string and number constants |
| true | JavaScript call optimizations |
| true | Move constant declarations closer to usage sites |
| true | Coalesce JavaScript variables with disjoint lifespans |
Option | Default | Description |
| false | Enable effect handlers |
| true | Wrap JavaScript exceptions in OCaml exceptions |
| false | Attach JavaScript stack traces to OCaml exceptions |
| true | Keep |
| true | Generate dummy primitives when missing |
| true | Use JavaScript strings internally |
Option | Default | Description |
| false | Include source location comments |
| false | Use stable (predictable) variable names |
| true | link required compilation units only |
Use --set <param>=<value> to tune compiler behavior:
Parameter | Default | Description |
| 60 | Max cases before switch becomes if-else chain |
| 150 | Size threshold for function inlining |
| 50 | Max tail-call depth before trampoline |
| trampoline | Tail-call mode: |
Option | Description |
| Suppress non-error messages |
| Treat warnings as errors |
| Enable warning |
| Disable warning |
Available warnings:
Warning | Default | Description |
| on | Missing JavaScript primitive implementation |
| on | Missing .cmi file |
| on | Missing dependencies |
| on | Using effects, but not backend was selected |
| on | Integer overflow in constant |
| on | Overriding an existing primitive |
| on | Using deprecated primitive |
| on | Free variables in primitive code |
Use --debug <section> to enable debug output for compiler internals:
times, stats, deadcode, globaldeadcode, inlining, constant-sinking, gen, linker, sourcemap, flow, parser, var-coalescing
The js_of_ocaml command has several subcommands:
Command | Description |
| Compile bytecode to JavaScript (default) |
| Link JavaScript files together |
| Build standalone runtime |
| Build pseudo filesystem |
The wasm_of_ocaml command has similar subcommands:
Command | Description |
| Compile bytecode to WebAssembly (default) |
| Link files together |
| Build standalone runtime |
js_of_ocaml link -o output.js runtime.js lib1.js lib2.js main.js
Additional options:
Option | Description |
| Build a library (.cma.js) |
| Resolve source map URLs |
js_of_ocaml build-runtime -o runtime.js
Accepts the same --enable/--disable options as the main command.
js_of_ocaml build-fs -o fs.js file1.txt file2.dat
Builds a JavaScript file containing filesystem data.