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.
Program.fs(5,9): error FS0039: The value or constructor 'printfnn' is not defined. Maybe you want one of the following:
printfn
printfCommon 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
- Use the compiler's suggestion list to pick the intended name.
- Add the needed
openso the member is in scope. - Re-run
dotnet build.
open System.IOFix 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.
<ItemGroup>
<Compile Include="Types.fs" />
<Compile Include="Program.fs" />
</ItemGroup>How to prevent it
- List fsproj
<Compile>items in dependency order. - Add
openstatements for every module a file uses. - Build locally; F# scope errors are deterministic and easy to reproduce.