Skip to content
Latchkey

Nim "Error: undeclared identifier" in CI

Nim could not resolve a name in the current scope. Either the module that defines it was never imported, or the symbol exists but was not exported from its module with a trailing asterisk.

What this error means

Compilation fails with "Error: undeclared identifier: X" pointing at the line that uses the name. Builds pass locally when the missing import happens to be supplied elsewhere.

nim
src/main.nim(7, 14) Error: undeclared identifier: 'parseConfig'

Common causes

The defining module was not imported

The symbol lives in another module that the current file does not import, so the name is unknown in this scope.

The symbol is not exported

Nim only exports identifiers marked with a trailing * (for example proc parseConfig*). Without it the proc is private to its own module.

How to fix it

Import the module that declares the name

  1. Find which module defines the identifier.
  2. Add an import for that module at the top of the file using it.
  3. Rebuild to confirm the name now resolves.
main.nim
import config   # brings parseConfig into scope

Export the symbol with an asterisk

Mark the proc, type, or var public so importers can see it.

config.nim
proc parseConfig*(path: string): Config =
  ## visible to other modules now
  discard

How to prevent it

  • Export public API symbols with a trailing asterisk.
  • Keep imports explicit at the top of each module.
  • Run nim check in CI to catch unresolved names early.

Frequently asked questions

What causes "Nim "undeclared identifier""?
The symbol lives in another module that the current file does not import, so the name is unknown in this scope.
How do I fix Nim "undeclared identifier"?
Import the module that declares 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