I know that solc can take remappings but I'm trying to force hardhat to take in my remappings.txt file each time it is compile. I've looked for a while and can't seem to find anything about that on their site as for remappings in the config files? Is there a good plugin for this? Can we simply just pass commandline arguments to hardhat? for the compilation process? Thanks

  • Hi, same problem here. Any luck finding an aswer?
    – EmmanuelB
    Commented Apr 7, 2022 at 11:26

1 Answer 1


In your hardhat.config.ts file you can use the preprocess option to include remappings.

Note that this doesn't use remappings in the solidity compiler, this updates the import references in each of your solidity files. If you need exact bytecode matches, this solution won't work due to source differences.

Original source: https://book.getfoundry.sh/config/hardhat

function getRemappings() {
  return fs
    .readFileSync("remappings.txt", "utf8")
    .filter(Boolean) // remove empty lines
    .map((line: string) => line.trim().split("="));

const config: HardhatUserConfig = {
  preprocess: {
    eachLine: (hre) => ({
      transform: (line: string) => {
        if (line.match(/".*.sol";$/)) { // match all lines with `"<any-import-path>.sol";`
          for (const [from, to] of getRemappings()) {
            if (line.includes(from)) {
              line = line.replace(from, to);
        return line;
  // ...

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.