Skip to content
Latchkey

Foundry "Compiler run failed" solc error in CI

forge invoked solc and solc returned one or more errors, so it prints "Compiler run failed" followed by each error with its code, file, and line. The individual solc errors are what must be fixed.

What this error means

forge build or forge test fails with "Error: Compiler run failed:" and per-file diagnostics such as Error (7576) or Error (9582) pointing at your Solidity source.

Foundry
Error: Compiler run failed:
Error (7576): Undeclared identifier.
  --> src/Vault.sol:22:13:
   |
22 |             owner = msgSender;
   |             ^^^^^

Common causes

A genuine Solidity error in the sources

An undeclared identifier, type error, or version-guarded feature makes solc reject a contract; the numbered error names the exact issue and location.

A solc version that does not match the code

The solc_version in foundry.toml (or an auto-detected version) does not support a language feature the contract uses.

How to fix it

Fix the numbered solc error

  1. Read the first Error (NNNN) block with its file and line.
  2. Correct the identifier, type, or syntax it reports.
  3. Re-run forge build until it reports no errors.
Terminal
forge build

Pin a compatible solc version

Set the compiler version in foundry.toml so it supports the code being compiled.

foundry.toml
[profile.default]
solc_version = "0.8.24"

How to prevent it

  • Run forge build locally before pushing.
  • Pin solc_version so CI uses a known-good compiler.
  • Fix warnings that mask real issues during review.

Related guides

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