Fable

raw JSON →
2.1.0-alpha-001 verified Fri May 01 auth: no javascript

Fable is an F# to JavaScript/TypeScript/Python/Dart/Rust/Erlang compiler. The current stable release is 4.29.0 with 5.0.0 in release candidate (rc.7). It is under active development, releasing multiple alpha/rc versions per month. Key differentiators: single codebase compiles to multiple targets, supports F# quotations, integrates with .NET tooling via dotnet CLI. The compiler is distributed as a .NET tool via NuGet.

error The type 'Fable.Cli' is not defined
cause Missing reference to Fable.Cli NuGet package.
fix
Add '#r "nuget: Fable.Cli"' before using Fable.Cli module.
error Unknown language 'beam'
cause Using an older Fable version that doesn't support BEAM/Erlang target.
fix
Upgrade to Fable >=5.0.0-rc.1 to use '--lang beam'.
error Fable.Core.Emit does not support this target
cause Using [<Emit>] attribute with Python or BEAM target.
fix
Use platform-specific interop or Fable.Core.JsInterop.
error Fable: Could not find 'fable-library.js'
cause Missing Fable library runtime files.
fix
Ensure you have added Fable.Library NuGet package and restored.
breaking Fable 5.0.0 renames the 'fable' command to 'fable-cli'. Use 'dotnet fable'.
fix Replace 'fable' with 'dotnet fable' in scripts and CI.
breaking Fable 5.0.0 changes default output format for Python/Beam targets; check generated files.
fix Review output directory structure and imports.
deprecated Fable 3.x 'fable-splitter' is deprecated; use Fable.Cli directly.
fix Migrate to Fable.Cli with 'dotnet fable'.
gotcha Fable.Core.Emit attribute does not work with Fable 5 Python/Beam targets; use Fable.Core.JsInterop instead.
fix Replace [<Emit>] with platform-specific interop attributes.
gotcha ResizeArray equality uses reference equality in Fable 5 for all targets; .NET uses structural equality.
fix Use FSharp.Core's List or Array for structural equality, or implement custom equality.
gotcha Fable does not support all .NET APIs; especially reflection and AppDomain.
fix Test your F# code against Fable's supported API subset.
npm install fable-compiler-dotnet
yarn add fable-compiler-dotnet
pnpm add fable-compiler-dotnet

Compiles the current F# file to JavaScript using Fable.Cli NuGet package.

#r "nuget: Fable.Cli"
open Fable.Cli

let output = 
    {
        Fable.CompilerOptions.Create() with
            file = __SOURCE_FILE__
            outDir = "./output"
            lang = Fable.Language.JavaScript
    }
Fable.Cli.compile output |> Async.RunSynchronously
|> function
| Ok _ -> printfn "Compilation succeeded"
| Error exn -> printfn "Error: %s" exn.Message