Skip to content
Latchkey

Nim "Error: cannot open file" in CI

Nim resolves each import to a .nim file on its search path and prints "Error: cannot open file" when no file matches. The name is a module path, not a package name, so a missing nimble path or a wrong directory is the usual cause.

What this error means

nim c or nimble build stops with "Error: cannot open file: X" naming the module it tried to import. The build never reaches code generation.

nim
/home/runner/work/app/app/src/main.nim(1, 8) Error: cannot open file: utils/config

Common causes

The module path does not match a file on disk

Nim imports resolve to files relative to the search path. import utils/config needs utils/config.nim reachable; a typo or a different directory layout makes it unresolvable.

A dependency path is not on the search path

A package installed by nimble is not on the compiler search path because the build did not run through nimble or the .nimble paths were not picked up.

How to fix it

Build through nimble so dependency paths are set

  1. Run the build with nimble build (or nimble c) so installed package paths are added to the search path.
  2. Confirm the imported module path matches a real .nim file relative to your source root.
  3. Add explicit search paths with --path: only if a directory is genuinely outside the project.
Terminal
nimble install --depsOnly
nimble build

Add a missing source directory to the path

If a local directory holds the module, point the compiler at it explicitly.

Terminal
nim c --path:src src/main.nim

How to prevent it

  • Run CI builds through nimble so dependency search paths are configured.
  • Keep import module paths matching the on-disk directory layout.
  • Commit a .nimble file that declares srcDir and dependencies.

Related guides

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