1

I am trying to import these lines on solidity and compile it with solc

import '@uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol';
import '@uniswap/v2-periphery/contracts/interfaces/IERC20.sol';

Every time I run the compile.js I get this error.

{"errors":[{"component":"general","formattedMessage":"mysample.sol:4:1: ParserError: Source \"@uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol\" not found: File import callback not supported\nimport '@uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol';
\n^-------------------------------------------------------------------------^
\n","message":"Source \"@uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol\" not found: File import callback not supported","severity":"error","sourceLocation":{"end":135,"file":"mysample.sol","start":60},"type":"ParserError"},
{"component":"general","formattedMessage":"mysample.sol:5:1: ParserError: Source \"@uniswap/v2-periphery/contracts/interfaces/IERC20.sol\" not found: File import callback not supported\nimport '@uniswap/v2-periphery/contracts/interfaces/IERC20.sol';
\n^-------------------------------------------------------------^
\n","message":"Source \"@uniswap/v2-periphery/contracts/interfaces/IERC20.sol\" not found: File import callback not supported","severity":"error","sourceLocation":{"end":200,"file":"mysample.sol","start":137},"type":"ParserError"}],"sources":{}}

The code for compile.js used

const path = require('path');
const fs = require('fs');
const solc = require('solc');

const mysamplePath = path.resolve(__dirname, 'contracts', 'mysample.sol');
const source = fs.readFileSync(mysamplePath, 'utf8');

console.log(solc.compile(
  JSON.stringify({
    language: "Solidity",
    sources: {
      "mysample.sol": {
        content: source
      }
    },
    settings: {
      outputSelection: {
        "*": {
          "*": ["evm", "bytecode"]
        }
      }
    }
  })
));

I have no idea why the compiler can not find the uniswap import. How do I resolve this?

3
  • Did you include the imports in the JSON imput to the compiler? – Ismael Oct 12 '20 at 3:05
  • i did not, how it would look like when adding the imports? – Marr Oct 12 '20 at 15:33
  • I'll add "<.sol path>": { content: <.sol content> } to the sources section for every imported file. – Ismael Oct 12 '20 at 17:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.