Compilation error in OpenZeppelin Contracts on Windows

Hi, I got a compilation error while doing npx oz compile and the error is @openzeppelin/contracts/ownership/Ownable.sol:3:1: ParserError: Source "@openzeppelin/contracts/GSN/Context.sol" not found: File import callback not supported import "../GSN/Context.sol";

And this is my simple smart contract,

pragma solidity ^0.5.0;

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

contract Storage is Ownable {
    uint256 private value;

    function setValue(uint256 _value) public onlyOwner {
        value = _value;
    }

    function getValue() public returns (uint256) {
        return value;
    }
}

I don’t know which part of the import statement is wrong. Is it in my contract or in openzeppelin’s one of the contracts? Any help would be appreciated :slight_smile:

2 Likes

Hi @manolingam,

Sorry to hear you are having an issue. The import appears ok.

What version of OpenZeppelin Contracts are you using? What operating system and versions of node and npm?

1 Like

Hi @abcoathup,

Am using OpenZeppelin Contracts v2.5.0 on a Windows machine with node v12.16.0 and npm v6.13.0.

1 Like

Hey @manolingam. I’ve just compiled your contract. It works fine. Do you compile with openzeppelin or truffle? Which versions do you use? What is your truffle.js or network.js file?

1 Like

I suggest looking at using WSL (this is what I use)

1 Like

Hello @ylv-io,
I compiled with openzeppelin and the command-line version is 2.7.2.

And here’s my network.js file,

module.exports = {
  networks: {
    development: {
      protocol: 'http',
      host: 'localhost',
      port: 8545,
      gas: 5000000,
      gasPrice: 5e9,
      networkId: '*',
    },
  },
};

I don’t know why I can’t compile. Getting the same error again.

1 Like

Hello @abcoathup,
I wanna use windows as my main development environment as I usually find it difficult to create a subsystem and manage resources for it. Hope someone helps me with the issue. And thanks for the suggestion anyways :slight_smile:

1 Like

Used your version still works fine for me. Which version of @openzeppelin/contracts": "^2.5.0" you use? What is inside of .openzeppelin/project.json? Which version of solc compiler it tries to use? ompiled contracts with solc 0.5.16 (commit.9c3226ce) for me.

1 Like

Hi @ylv-io and @manolingam,

The issue appears to be developing natively with Windows.
I vaguely remember (two years ago) having to swap the from / to \ in import statements though I haven’t been able to find any documentation on this.

I’m running Windows Subsystem for Linux with no issues. I unfortunately don’t have a pure Windows environment that I can use to reproduce at the moment.

An alternative for experimentation is to use Remix with GitHub imports (see Deploy a simple ERC20 token in Remix)

In production the Windows recommendation is to use Windows Subsystem for Linux. (see https://docs.microsoft.com/en-us/windows/nodejs/setup-on-windows#use-windows-subsystem-for-linux-for-production)

1 Like

Hello @ylv-io,
Are you using windows? Also, I have attached below some screenshots for your reference.

Thanks for your response too @abcoathup. Since Igor can compile successfully in his environment, I wanna know what went wrong in mine. So, I would use Windows Subsystem as a secondary environment.

2 Likes

Hey @manolingam. You setup is perfectly valid. Unfortunately at that moment we don’t support windows as a platform directly. Your options would be to try Windows Subsystem for Linux or other platforms. I am sorry for inconvenience.

2 Likes

Hello @ylv-io, I will then try some linux. Thanks for the help. But also, did my code compile good on your plain windows machine?

2 Likes

Hey @manolingam! I personally use Mac Os.

1 Like

Hi @manolingam,

I am the Windows user in the team and after doing smart contract development on Windows 7 in 2017/2018, have used Windows Subsystem for Linux since 2018+ and haven’t looked back. I would encourage using WSL, and Microsoft’s recommendation is to use WSL for node projects for production.

A post was split to a new topic: Truffle compile error importing OpenZeppelin Contracts

A post was split to a new topic: Compile error on MacOS