I am using Juan Blanco’s Solidity plugin. I think I’ve resolved this by defining the path to the imports in my compile.js:
const path = require("path");
const fs = require("fs-extra");
const solc = require("solc");
const resolvePath = require("./path-resolve");
const buildPath = path.resolve(__dirname, "build");
fs.removeSync(buildPath);
// All files imported in the contract
const paths = resolvePath({
"ERC20.sol": "../node_modules/@openzeppelin/contracts/token/ERC20/ERC20.sol",
"math/SafeMath.sol":
"../node_modules/@openzeppelin/contracts/math/SafeMath.sol",
"GSN/Context.sol": "../node_modules/@openzeppelin/contracts/GSN/Context.sol",
"IERC20.sol":
"../node_modules/@openzeppelin/contracts/token/ERC20/IERC20.sol",
});
const tokenSalePath = path.resolve(__dirname, "contracts", "SMPTokenSale.sol");
const smpTokenSale = fs.readFileSync(tokenSalePath, "utf-8");
const input = {
language: "Solidity",
sources: {
"SMPTokenSale.sol": {
content: smpTokenSale,
},
},
settings: {
outputSelection: {
"*": {
"*": ["*"],
},
},
},
};
function findImports(path) {
if (paths[path]) return { contents: paths[path] };
else return { error: "File not found" };
}
const output = JSON.parse(
solc.compile(JSON.stringify(input), { import: findImports })
).contracts;
fs.ensureDirSync(buildPath);
for (let contract in output) {
fs.outputJSONSync(
path.resolve(buildPath, contract.replace(":", "") + ".json"),
output[contract]
);
}
This seemed to have resolved the errors.