Fable
raw JSON → 2.13.0 verified Fri May 01 auth: no javascript
Fable is an F# to JavaScript/TypeScript, Python, Dart, Rust, and Erlang/Elixir (BEAM) compiler. Current stable version is 2.13.0 (npm package for CLI integration) with compiler core at v5.0.0. The project releases frequently with alphas/RCs. Unlike F# Compiler Services directly, Fable translates F# into clean, readable code for multiple targets. Key differentiator: it covers F#-to-multiple-backends in one tool, with growing language support including quotations and inlining. Note: npm 'fable-compiler' package is a wrapper for JS-based tooling; the actual compiler is the dotnet tool 'fable'.
Common errors
error Cannot find module 'fable-library' ↓
cause The fable-library npm package is not installed or not in node_modules.
fix
Run: npm install fable-library
error error FS3033: The fable-compiler package is not compatible with the .NET SDK version ↓
cause Incompatible .NET SDK version (Fable 5 requires .NET 8+).
fix
Install .NET 8 SDK from dotnet.microsoft.com and update global.json if present.
error Error: 'emit' is not defined (in browser) ↓
cause Using 'emit' macro or Fable.Core attributes without appropriate import or polyfill.
fix
Ensure Fable.Core is imported: import { emitExpr } from 'fable-core'
Warnings
breaking Fable 5 requires .NET 8 SDK and has breaking changes in target output; references to Fable.Core libraries must be updated. ↓
fix Update .NET SDK to 8.0+, check migration guide for changes in generated code.
deprecated The 'fable-compiler' npm package is deprecated in favor of dotnet tool; direct npm usage for compilation is discouraged. ↓
fix Use 'dotnet fable' command instead of 'fable-compiler' CLI.
gotcha String interpolation format specifiers may be dropped or cause compilation errors in non-JS targets (Python, Dart, Rust, BEAM). ↓
fix Review interpolated strings in code; use format functions where specifiers are required.
gotcha Fable does not support all .NET APIs; you must use Fable-specific equivalents (e.g., 'FSharp.Collections.Array' instead of 'System.Array'). ↓
fix Refer to Fable-friendly library replacements; use 'Fable.Core' and 'fable-library'.
breaking From v5.0.0-rc.6: Python modulo behavior for bigint changed from truncated (.NET semantics) to floored (Python semantics), breaking existing code. ↓
fix If using modulo on bigint in Python target, adjust logic to expect Python-style floored division.
Install
npm install fable-compiler yarn add fable-compiler pnpm add fable-compiler Imports
- default and named exports (JS/TS) wrong
import fableModule from './fsharp-module'correctimport { add, multiply } from './fsharp-module' - FSharpRef wrong
import { FSharpRef } from 'fable-library'correctimport { FSharpRef } from 'fable-library/Builtins' - Fable.Core types wrong
import { emitExpr } from 'fable-library'correctimport { emitExpr } from 'fable-core'
Quickstart
// 1. Install Fable dotnet tool:
// > dotnet tool install --global fable
// 2. Create an F# project with fable.config.json
// Example fable.config.json:
// {
// "sourceMaps": true,
// "target": "javascript"
// }
// 3. Compile F# to JavaScript:
// > dotnet fable fsharp-project.fsproj --outDir ./output --lang js
// 4. In your JavaScript:
// import { greet } from './output/MyModule.js';
// console.log(greet("World"));