Whenever I try to compile my solidity contract, the error ParserError: Source \"@OpenZeppelin/contracts/math/SafeMath.sol\" not found: File import callback not supported gets thrown.
pragma solidity ^0.7.0;
import "@OpenZeppelin/contracts/token/ERC20/ERC20.sol";
import "@OpenZeppelin/contracts/math/SafeMath.sol";
Any ideas what could be causing this?
I have the same problem right now. I'm using truffle+node and I fixed it modifying the import path to a relative path, for example,
pragma solidity ^0.7.0;
import "../node_modules/OpenZeppelin/contracts/token/ERC20/ERC20.sol";
import "../node_modules/OpenZeppelin/contracts/math/SafeMath.sol";
I'm not 100% sure why this happen but I hope I helped you.
For some environments, SafeMath has a different path
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
actualy the problem is solidity compiler is stupid and doesn't automatically follow path, you have to specify all allowed path manually (https://docs.soliditylang.org/en/latest/using-the-compiler.html), every each one of them and completely to the file(cannot give juste the higher level folder) use npx hardat compile if you can it's better
After installing OpenZeppelin close your IDE and re-open it.
Make sure you opened VS Code in the root directory of the project.
In my case, this is how my VS Code directory looked like when I get that same error.
projects
|___MyContract
|__contracts
|__Contract.sol
Reopening VS Code in the MyContract directory fixes it.
MyContract
|__contracts
|__Contract.sol
what worked for me; (I am using Windows10 and visual studio code) -click on the extensions icon -search for the solidity extension -select the uninstall button and click on the drop down arrow -select install another version -select version 0.0.135 -After the installation, click on "Reload required"