0

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

3 Answers 3

0

change your import statement to

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

and then check

1
  • I have edited my question. I started with this, but it gave me an error from the code editor Mar 4, 2022 at 11:15
0

Try importing it like this because i found this from the OpenZeppelin Documentation

import "@openzeppelin/contracts/access/Ownable.sol";
1
  • I have edited my question. I started with this, but it gave me an error from the code editor Mar 4, 2022 at 11:15
0

Issue fixed. I had to copy the entire @openzeppelin folder from node_modules and paste in the root directory of my contracts folder.

3
  • 1
    that's an awful fix
    – ihor.eth
    May 13, 2022 at 23:24
  • Thanks. youve been very helpful May 15, 2022 at 5:17
  • Post a small reproduction repo on Github. It's hard to help based on the little info you've provided. My bet is that your folder structure is wrong.
    – ihor.eth
    May 16, 2022 at 14:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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