Skip to content
Latchkey

solc "Source ... not found: File not found" in CI

solc resolved an import to a filesystem path and no file exists there. The import path, a remapping, or the include directories passed to solc do not point at the real location of the imported source.

What this error means

Compilation fails with "Error: Source \"X\" not found: File not found" pointing at an import line in one of your contracts.

solc
Error: Source "@openzeppelin/contracts/token/ERC20/ERC20.sol" not found: File not found.
 --> contracts/Token.sol:4:1:
  |
4 | import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Common causes

The dependency is not installed

The imported package (for example OpenZeppelin) is not present in node_modules or the vendored path, so the file does not exist.

A missing remapping or include path

solc was not told how to map the import prefix to a directory, so it looks in the wrong place and finds nothing.

How to fix it

Install the dependency and set the path

  1. Install the imported package so its files exist on disk.
  2. Pass the correct base path or remapping to solc.
  3. Re-run the compile so the import resolves.
Terminal
npm install @openzeppelin/contracts
solc --base-path . --include-path node_modules contracts/Token.sol

Add an explicit remapping

Map the import prefix to its directory so solc resolves it consistently.

remappings.txt
@openzeppelin/=node_modules/@openzeppelin/

How to prevent it

  • Install contract dependencies before compiling in CI.
  • Keep remappings and include paths accurate.
  • Compile from a clean checkout to catch missing sources.

Related guides

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