Skip to content
Latchkey

dune "Error: Unbound constructor" in CI

The compiler saw a constructor name with no matching variant in scope. Usually the type that defines it is in an unopened module, or the installed library version renamed or removed the constructor.

What this error means

dune build fails with "Error: Unbound constructor X", often after a dependency upgrade changed a variant type.

dune
File "lib/state.ml", line 12, characters 4-11:
12 |   | Pending -> ...
         ^^^^^^^
Error: Unbound constructor Pending

Common causes

The type is defined in an unopened module

The constructor belongs to a variant in another module that was not opened, so its bare name is not in scope.

The variant changed across a library version

CI resolved a version where the constructor was renamed or removed, so code that compiled locally fails here.

How to fix it

Qualify the constructor or open its module

  1. Reference the constructor through its module, e.g. Status.Pending.
  2. Or add open Status at the top of the file.
  3. Rebuild to confirm the constructor resolves.
lib/state.ml
open Status
let x = Pending

Align the library version

If the variant changed between releases, pin the version whose constructors match your code.

Terminal
opam pin add status_lib 2.1.0 --yes

How to prevent it

  • Qualify or open the module that defines a variant type.
  • Pin library versions so variant definitions stay stable in CI.
  • Review changelog entries before bumping dependency versions.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →