Error importing OpenZeppelin contracts in vscode

Hi,

I was following the OpenZepellin doc on developing smart contracts and after installing truffle (in my current working directory) with command

npx truffle init

I then tried installing the OpenZeppelin contracts library (also in my current working directory) with command

npm install --save-dev @openzeppelin/contracts

it seemed like it worked, but then when I try importing the Ownable contract in my contracts folder in VSCode, with the command

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

i get this

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

Thing is, I can’t even see a folder showing the several solidity files for the OpenZeppelin contracts library in my folder, so I’m not even sure where it was installed.

Any idea what I might have done wrong?

I think if you have installed @openzeppelin/contracts successfully, this package should show at:

-Your Contract Project
  -node_modules
    -@openzeppelin
      -contracts
        -access
          -Ownable.sol
1 Like

hi,

I don’t have this package in my project. I’m not sure what else to do as it seemed to have installed successfully.

I am not sure whether you need a package.josn at first, then you can run npm install --save-dev @openzeppelin/contracts, if you have installed successfully, the dependency @openzeppelin should be in the node_modules

image

1 Like

it says this btw, not sure what it means

chika@Chikas-MacBook-Pro cryptoTomb % npm install --save-dev @openzeppelin/contracts
npm WARN chika@1.0.0 No description
npm WARN chika@1.0.0 No repository field.

+ @openzeppelin/contracts@4.0.0
updated 1 package and audited 1 package in 0.604s
found 0 vulnerabilities
1 Like

So how about running truffle compile now?

1 Like

Hi @ch1ka,

Try creating a package.json using npm init -y: https://docs.openzeppelin.com/learn/setting-up-a-node-project