Skip to content
Latchkey

F# "error FS0039: ... is not defined" in CI

The F# compiler reached a name that is not in scope. FS0039 means the value, constructor, or module member is undefined here: a missing open, a typo, or use before declaration in F#'s top-to-bottom order.

What this error means

dotnet build or fsc fails with "error FS0039: The value or constructor X is not defined." pointing at the reference.

F#
Program.fs(5,9): error FS0039: The value or constructor 'printfnn' is not defined. Maybe you want one of the following:
   printfn
   printf

Common causes

A typo or missing open

The name is misspelled, or the module that defines it was not brought into scope with open.

Use before declaration

F# processes files and bindings top to bottom; referencing a value defined later (or in a file listed later) leaves it undefined at the use site.

How to fix it

Open the module or fix the name

  1. Use the compiler's suggestion list to pick the intended name.
  2. Add the needed open so the member is in scope.
  3. Re-run dotnet build.
Program.fs
open System.IO

Fix declaration order

Move the definition above its first use, and ensure files are listed in the right order in the fsproj <Compile> items, since F# is order-sensitive.

App.fsproj
<ItemGroup>
  <Compile Include="Types.fs" />
  <Compile Include="Program.fs" />
</ItemGroup>

How to prevent it

  • List fsproj <Compile> items in dependency order.
  • Add open statements for every module a file uses.
  • Build locally; F# scope errors are deterministic and easy to reproduce.

Frequently asked questions

What causes ""error FS0039: ... is not defined""?
The name is misspelled, or the module that defines it was not brought into scope with open.
How do I fix "error FS0039: ... is not defined"?
Open the module or fix the name

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card