Truffle compile error importing OpenZeppelin Contracts

Hey, i just started using WSL on VS Code.
Before that, 5mins ago i was using normal windows environment.

In both the environments, i am unable to compile my truffle project and it looks like and error in the openzepplin .sol file’s import statements.

Can you help?

1 Like

Hi @Rahul_Gupta,

Welcome to the community :wave:

I’m sorry that you are having this issue when compiling with Truffle.

I am using WSL2 and wasn’t able to reproduce what you are seeing.


pragma solidity ^0.6.0;

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

contract GLDToken is ERC20 {
    constructor(uint256 initialSupply) ERC20("Gold", "GLD") public {
        _mint(msg.sender, initialSupply);

Truffle compile

$ npx truffle compile

Compiling your contracts...
> Compiling ./contracts/GLDToken.sol
> Compiling ./contracts/Migrations.sol
> Compiling @openzeppelin/contracts/GSN/Context.sol
> Compiling @openzeppelin/contracts/math/SafeMath.sol
> Compiling @openzeppelin/contracts/token/ERC20/ERC20.sol
> Compiling @openzeppelin/contracts/token/ERC20/IERC20.sol
> Compiling @openzeppelin/contracts/utils/Address.sol
> Artifacts written to /home/abcoathup/projects/forum/rahul_gupta/build/contracts
> Compiled successfully using:
   - solc: 0.6.7+commit.b8d736ae.Emscripten.clang

Project in VSCode

Would you mind running npx truffle version (if truffle installed locally) or truffle version if installed globally.

I have the following versions:

$ npx truffle version
Truffle v5.1.26 (core: 5.1.26)
Solidity - 0.6.7 (solc-js)
Node v10.19.0
Web3.js v1.2.1

How are you running the compile?
I use npx truffle compile.

Hi @Rahul_Gupta,

I wanted to check if you were able to resolve? Please ask all the questions that you need.