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
- Install the imported package so its files exist on disk.
- Pass the correct base path or remapping to solc.
- Re-run the compile so the import resolves.
Terminal
npm install @openzeppelin/contracts
solc --base-path . --include-path node_modules contracts/Token.solAdd 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
solc "TypeError: not implicitly convertible" in CIFix Solidity "TypeError: Type X is not implicitly convertible to expected type Y" in CI - a value was used wh…
Foundry "failed to resolve file / source not found" import error in CIFix Foundry "failed to resolve file" / "Source not found" in CI - forge cannot locate an imported file, usual…
solc "DeclarationError: Identifier not found or not unique" in CIFix Solidity "DeclarationError: Identifier not found or not unique" in CI - solc could not resolve a name bec…