Fable: F# to JavaScript Compiler

raw JSON →
0.7.42 verified Fri May 01 auth: no javascript

Fable is an F# to JavaScript compiler that leverages the F# compiler service and Babel to emit clean, readable JavaScript. It compiles F# source code directly (no .NET bytecode), includes a minimal runtime (~20KB min+gzip), and integrates with the JavaScript ecosystem (ES6 modules, npm, Webpack). Current stable version is 5.0.0 (released 2024-08). Release cadence: major versions (4.x, 5.x) have been stable for years; pre-release RCs and alphas are frequent (multiple per month). Differentiators: F# fidelity (most F# core library, quotations, type providers), multi-target (JS, TS, Python, Dart, Rust, Erlang/BEAM), and no runtime overhead.

error fable: command not found
cause Installed package 'fable' instead of 'fable-compiler'.
fix
Install fable-compiler: npm install -g fable-compiler
error Cannot find module 'fable-compiler'
cause Running 'fable' before installing, or installed locally not globally.
fix
Install globally: npm install -g fable-compiler, or use npx: npx fable-compiler
error The type 'Fable.Core.ImportAttribute' is not defined
cause Missing reference to Fable.Core NuGet package.
fix
Add <PackageReference Include="Fable.Core" Version="*" /> to .fsproj
breaking Options are erased — "None" becomes null/undefined, "Some x" becomes x.
fix Use pattern matching or Option module functions instead of null checks on options.
breaking Fable 3.0 renamed package from "fable-compiler" to "fable"? Actually the package is still "fable-compiler"; the CLI command is "fable".
fix Install with 'npm install -g fable-compiler'; run with 'fable'.
gotcha Fable target languages: JavaScript (default), TypeScript, Python, Dart, Rust, Erlang/BEAM. Use --lang flag.
fix Specify target language explicitly: 'dotnet fable --lang TypeScript'.
deprecated Legacy Fable 1.x and 2.x are obsolete; .NET Framework requirement vs .NET Core/5+.
fix Upgrade to Fable 4.x or 5.x and use .NET SDK (net8.0+).
gotcha Fable 5.0.0-rc released Aug 2024; stable 5.0.0 is final. Ensure compatibility with F# 8 and .NET 8.
fix Use F# 8 and .NET 8 SDK for Fable 5.0+.
breaking Fable 5.0.0 final: Python target now uses len() instead of .length for ResizeArray (breaking).
fix Update Python-specific code expecting .length property; use len() or .Length (which maps to len()).
npm install fable-compiler-netcore
yarn add fable-compiler-netcore
pnpm add fable-compiler-netcore

Shows minimal F# project setup with Fable, including fsproj, Fable.Core reference, and CLI compilation.

// Create a simple F# project
// 1. Create project.fsproj with:
// <Project Sdk="Microsoft.NET.Sdk">
//   <PropertyGroup>
//     <TargetFramework>net8.0</TargetFramework>
//   </PropertyGroup>
//   <ItemGroup>
//     <Compile Include="Program.fs" />
//     <PackageReference Include="Fable.Core" Version="4.0.0-beta-*" />
//   </ItemGroup>
// </Project>

// 2. Create Program.fs with:
module Program

open Fable.Core

[<EntryPoint>]
let main argv =
    printfn "Hello from Fable!"
    0

// 3. Compile:
// dotnet fable --lang JavaScript --outDir output

// 4. Run output/Program.js with Node