I know how to install solc via "npm install --save solc" then use solc.compile to compile one sol file. But now I've got A.sol file that imports B.sol file, and when I run node compile.js, no error in my terminal, but no json file is generated!

But when I use the same compile.js to compiile B.sol, it works. Why??? How to fix this importing feature in Solidity sol files??? Thank you.

const pathA = path.resolve(__dirname, 'contracts', 'A.sol');
//to find the path of A.sol inside the folder 'contract' in your project
const pathB = path.resolve(__dirname, 'contracts', 'B.sol');
const solA = fs.readFileSync(pathA, 'utf8');
const solB = fs.readFileSync(pathB, 'utf8');

const input = {
  sources: {
    'A.sol': solA,
    'B.sol': solB
console.log(solc.compile(input, 1));

I have been unable to get solc js to import .sol files into eachother - I'm not sure if it's possible. My workaround is to just combine all .sol files into one single file and compile that.

See this question.

Your Answer

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

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