OpenZeppelin CLI compilation errors when importing OpenZeppelin Contracts on Windows 8

Hello. I’m trying to follow this tutorial, in order to get familiar with the openzeppelin SDK. I have been able to develop, deploy and mint an ERC-721 token using the truffle suite, but I felt like giving this other toolbox a try.

I have been able to compile the simple version of the Box contract.

// contracts/Box.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;


contract Box {
    uint256 private value;

    // Emitted when the stored value changes
    event ValueChanged(uint256 newValue);

    // Stores a new value in the contract
    function store(uint256 newValue) public {
        value = newValue;
        emit ValueChanged(newValue);
    }

    // Reads the last stored value
    function retrieve() public view returns (uint256) {
        return value;
    }
}

However, whenever I try to add dependencies I get compilation errors. I would like to include the “Ownable.sol” file from the OpenZeppelin library, to follow the tutorial, but it is giving me the following error.

// contracts/Box.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;

// Import Ownable from the OpenZeppelin Contracts library
import "@openzeppelin/contracts/access/Ownable.sol";

// Make Box inherit from the Ownable contract
contract Box is Ownable {

    uint256 private value;
    event ValueChanged(uint256 newValue);

    // The onlyOwner modifier restricts who can call the store function
    function store(uint256 newValue) public onlyOwner {
        value = newValue;
        emit ValueChanged(newValue);
    }

    function retrieve() public view returns (uint256) {
        return value;
    }
}

Compile error

It is weird, because the error is about a dependency of the “Owner.sol” contract, if I am not mistaking, which means that Owner.sol is correctly being imported into Box.sol.

I have installed the contracts with:

npm install --save-dev @openzeppelin/contracts

Even the intellicense plugin in Visual Studio Code can find the path to the file, but the compiler does not.

:computer: Environment

I’m using Windows 8.1 (I’ve seen there are a lot of problems with windows) and the version 2.8.2 of the SDK.

:1234: Code to reproduce

All of the code being used is exactly the same as the one described in the tutorial.

2 Likes

Hello @Skyway, welcome to the forum! Feel free to Introduce yourself here! to the rest of the community :slight_smile:

Thanks for such a detailed issue report, let me try to reproduce it and get back to you.

1 Like

Hi! Thank you very much for your response.

I have installed an Ubuntu VM with VirtualBox, since I saw it was recommended. Now I’m about to finish the tutorial, so it is definitely an issue with Windows 8.1.

2 Likes

Right, I was unable to reproduce it in macOS :confused:

I’m glad you’re making progress now.

1 Like

Hi @Skyway,

Welcome to the community :wave:

Glad you are up and running using Linux. I use WSL2 (Windows Subsystem for Linux) on Windows 10. Whilst I did develop smart contracts using Windows 7 a couple of years ago, I used to run into problems regularly which I didn’t get on Linux.

1 Like