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.
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
- Read the first
Error (NNNN)block with its file and line. - Correct the identifier, type, or syntax it reports.
- Re-run
forge builduntil it reports no errors.
forge buildPin a compatible solc version
Set the compiler version in foundry.toml so it supports the code being compiled.
[profile.default]
solc_version = "0.8.24"How to prevent it
- Run
forge buildlocally before pushing. - Pin
solc_versionso CI uses a known-good compiler. - Fix warnings that mask real issues during review.