Skip to content
Latchkey

Haskell stack "While building package" in CI

stack invoked the build for a package and the underlying GHC/Setup process exited non-zero. The "While building package" banner identifies which package failed; the real compiler error is in the logged output above it.

What this error means

stack build stops with "While building package X-1.2.3 ..." and "Process exited with code: ExitFailure (1)", preceded by a GHC error or a missing system dependency.

Haskell
--  While building package zlib-0.6.3.0 using:
      /root/.stack/setup-exe-cache/.../Cabal-simple ... build --ghc-options ...
    Process exited with code: ExitFailure 1
    zlib.h: No such file or directory

Common causes

A missing system library for a package with C bindings

Packages like zlib or postgresql-libpq need their -dev system libraries; a slim runner image omits them, so the build fails.

A compile error in the package being built

A GHC type or scope error in your package or a dependency caused the build process to exit non-zero.

How to fix it

Install the system dependency the build names

  1. Read the GHC/C error above the "While building package" banner.
  2. Install the missing -dev system library before stack.
  3. Re-run stack build.
Terminal
sudo apt-get update
sudo apt-get install -y zlib1g-dev libpq-dev

Reproduce and fix the compile error locally

Build the failing package alone so the GHC error is isolated, then fix the code or pin a working version.

Terminal
stack build zlib --verbose

How to prevent it

  • Install required -dev system libraries before stack build.
  • Cache ~/.stack and .stack-work so builds are incremental.
  • Pin a resolver so the dependency set is reproducible.

Related guides

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