VSCode cannot import any openzepplin contracts

Im trying to get started with what should be a very simple contract but VSCode is giving me a hard time.
I'm using Juan Blancos solidity plugin but VSCode cannot find openzepplin imports

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

The error is:

Source "@openzeppelin/contracts/token/ERC20/ERC20.sol" not found: File import callback not supported

Even though vscode shows red squigglies I can compile successfully via hardhat compile.

If I change the path to

import "../node_modules/@openzeppelin/contracts/token/ERC20/ERC20.sol";

VScode stops complaining but then I cannot compile via hardhard, with the error being:

Source "node_modules/@openzeppelin/contracts/security/Pausable.sol" not found: File outside of allowed directories.

My VSCode settings for Solidity extension for both User and Workspace are:

"solidity.packageDefaultDependenciesContractsDirectory": "contracts",
"solidity.packageDefaultDependenciesDirectory": "node_modules"

Which corresponds to my project structure

root 
 |_ contracts
    |_ MyToken.sol
 |_ node_modules
    |_ @openzepplin

I followed the instructions here and have done extensive researching but unfortunately can't get it to working.

Thanks

Hi, welcome! :wave:

I think if you can run hardhat compile to compile the contract without any errors, that means your contract is ok, as for the error of the VS Code plugin, I am not sure, I usually ignore them, lol. Maybe there is some wrong with this plugin.

1 Like

Do you have the package listed in the package.json file?

I think the same error shows when you are trying to verify your contract using vscode.

Yes, I have

"dependencies": {
    "@openzeppelin/contracts": "^4.0.0"
  }

Screen Shot 2021-04-30 at 5.33.30 AM
how can I ignore that. it’s like razor blades on my eyes :roll_eyes:

open node_modules dir in your project folder and search for "@openzepplin" under that find "contracts" if not found run this command

npm install @openzeppelin/contracts

then you will see it resolved and not showing an error.