hardhat-docker icon indicating copy to clipboard operation
hardhat-docker copied to clipboard

Unable to compile a contract that is importing libraries from node_module.

Open Madeindreams opened this issue 2 years ago • 1 comments
trafficstars

Greeting.

I was looking into this. Thanks for the example. Would you know how I can import some contract from the open zeppelin library?

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

these imports statement are failing with

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

So the compilation fail. The node_module folder is created because the node will start but for some reason the imported path are not working inside the contract.

Any suggestion?

Madeindreams avatar Aug 04 '23 04:08 Madeindreams

Hi @Madeindreams I might recommend using the following to see how OpenZeppelin does imports.

https://wizard.openzeppelin.com

As a base though, you should just be able to do the following in your solidity contract.

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;

import "[@openzeppelin/contracts/token/ERC20/ERC20.sol](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.9.3/contracts/token/ERC20/ERC20.sol)";

contract MyToken is ERC20 {
    constructor() ERC20("MyToken", "MTK") {}
}

codingwithmanny avatar Aug 05 '23 11:08 codingwithmanny