NPX hardhat compile failing

contract-deploymenthardhathardhat-deploy

I am following the OpenZeppelin docs for deploying a smart contract. but when i run

npx hardhat compile

i get this error

ParserError: Source "node_modules/@openzeppelin/contracts/access/Ownable.sol" not found: File outside of allowed directories.
–> contracts/Transactions.sol:5:1:

I have installed the openzepellin contracts library and i have checked manually to see if the file i am requiring in my contract exists. It does. I import it like this

import "../node_modules/@openzeppelin/contracts/access/Ownable.sol";

NB trying to import with this line

import "@openzeppelin/contracts/access/Ownable.sol";

results in my code editor throwing this warning (the compile command also fails)

Source "@openzeppelin/contracts/access/Ownable.sol" not found: File import callback not supported

Best Answer

change your import statement to

import "@openzeppelin/contracts/access/Ownable.sol"; 

and then check

Related Topic