I failed to compile a solidity file with import statement.

Error: Source not found: File not found. import './contract.sol';

How should we set a import path?

I used web3.js for compiling.


Layout of a Solidity Source File — Solidity 0.2.0 documentation http://solidity.readthedocs.org/en/latest/layout-of-source-files.html

  • What happens if you use the absolute/full path, like /home/nakanishi/lorem/contract.sol ?
    – q9f
    Mar 18, 2016 at 13:41
  • Use the normal compiler. Mar 19, 2016 at 16:24

1 Answer 1


Files and paths are explained in detail here: http://solidity.readthedocs.org/en/latest/layout-of-source-files.html

Key points:


In import "filename";, filename is always treated as a path with / as directory separator, . as the current and .. as the parent directory. Path names that do not start with . are treated as absolute paths.

To import a file x from the same directory as the current file, use import ”./x” as x;.

Use in actual Compilers

When the compiler is invoked, it is not only possible to specify how to discover the first element of a path, but it is possible to specify path prefix remappings so that e.g. github.com/ethereum/dapp-bin/library is remapped to /usr/local/dapp-bin/library and the compiler will read the files from there. If remapping keys are prefixes of each other, the longest is tried first. This allows for a “fallback-remapping” with e.g. “” maps to “/usr/local/include/solidity”.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.