"File import callback not supported" on Truffle using Linux

I’m trying to compile a smart contract TestMinter.sol that inherits from ERC20PresetMinterPauser.sol using the @openzeppelin/contracts library and Truffle. TestMinter.sol seems to import the ERC20PresetMinterPauser.sol correctly using

import "node_modules/@openzeppelin/contracts/presets/ERC20PresetMinterPauser.sol";

But then when ERC20PresetMinterPauser.sol tries to import I get a File import callback not supported error:

$ truffle compile

Compiling your contracts...
===========================
> Compiling ./contracts/Migrations.sol
> Compiling ./contracts/TestMinter.sol
> Compiling ./node_modules/@openzeppelin/contracts/GSN/Context.sol
> Compiling ./node_modules/@openzeppelin/contracts/access/AccessControl.sol
> Compiling ./node_modules/@openzeppelin/contracts/math/SafeMath.sol
> Compiling ./node_modules/@openzeppelin/contracts/token/ERC20/ERC20.sol
> Compiling ./node_modules/@openzeppelin/contracts/token/ERC20/ERC20Burnable.sol
> Compiling ./node_modules/@openzeppelin/contracts/token/ERC20/ERC20Pausable.sol
> Compiling ./node_modules/@openzeppelin/contracts/token/ERC20/IERC20.sol
> Compiling ./node_modules/@openzeppelin/contracts/utils/Address.sol
> Compiling ./node_modules/@openzeppelin/contracts/utils/EnumerableSet.sol
> Compiling ./node_modules/@openzeppelin/contracts/utils/Pausable.sol
> Compiling node_modules/@openzeppelin/contracts/presets/ERC20PresetMinterPauser.sol

CompileError: node_modules/@openzeppelin/contracts/presets/ERC20PresetMinterPauser.sol:5:1: ParserError: Source "node_modules/@openzeppelin/contracts/access/AccessControl.sol" not found: File import callback not supported
import "../access/AccessControl.sol";
^-----------------------------------^
,node_modules/@openzeppelin/contracts/presets/ERC20PresetMinterPauser.sol:6:1: ParserError: Source "node_modules/@openzeppelin/contracts/GSN/Context.sol" not found: File import callback not supported
import "../GSN/Context.sol";
^--------------------------^
,node_modules/@openzeppelin/contracts/presets/ERC20PresetMinterPauser.sol:7:1: ParserError: Source "node_modules/@openzeppelin/contracts/token/ERC20/ERC20.sol" not found: File import callback not supported
import "../token/ERC20/ERC20.sol";
^--------------------------------^
,node_modules/@openzeppelin/contracts/presets/ERC20PresetMinterPauser.sol:8:1: ParserError: Source "node_modules/@openzeppelin/contracts/token/ERC20/ERC20Burnable.sol" not found: File import callback not supported
import "../token/ERC20/ERC20Burnable.sol";
^----------------------------------------^
,node_modules/@openzeppelin/contracts/presets/ERC20PresetMinterPauser.sol:9:1: ParserError: Source "node_modules/@openzeppelin/contracts/token/ERC20/ERC20Pausable.sol" not found: File import callback not supported
import "../token/ERC20/ERC20Pausable.sol";
^----------------------------------------^

Compilation failed. See above.
    at run (/home/contooter/.npm-global/lib/node_modules/truffle/build/webpack:/packages/compile-solidity/run.js:52:1)
    at Object.sourcesWithDependencies (/home/contooter/.npm-global/lib/node_modules/truffle/build/webpack:/packages/compile-solidity/index.js:107:56)
    at necessary (/home/contooter/.npm-global/lib/node_modules/truffle/build/webpack:/packages/compile-solidity/index.js:69:1)
    at /home/contooter/.npm-global/lib/node_modules/truffle/build/webpack:/packages/workflow-compile/index.js:33:1
    at async Promise.all (index 0)
    at compile (/home/contooter/.npm-global/lib/node_modules/truffle/build/webpack:/packages/workflow-compile/index.js:23:1)
    at Object.compile (/home/contooter/.npm-global/lib/node_modules/truffle/build/webpack:/packages/workflow-compile/index.js:66:45)
Truffle v5.1.57 (core: 5.1.57)
Node v14.15.1

:computer: Environment

Truffle v5.1.57 (solc 0.6.2)
Node v14.15.1
@openzeppelin/contracts 3.3.0
Linux Mint 20

I could probably do a workaround and change all the smart contracts import paths to full paths but I rather not mess around with the preconfigured contracts from OZ because of security reasons.

1 Like

I am not sure, but I think if you have installed the package, you can use as following:

pragma solidity ^0.5.0;

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

contract SimpleToken is Context, ERC20, ERC20Detailed {
    constructor () public ERC20Detailed("SimpleToken", "SIM", 18) {
        _mint(_msgSender(), 1000000 * (10 ** uint256(decimals())));
    }
}

Just show a simple code to use OpenZeppelin dependency.

2 Likes

Hi @Lennard_Mulder,

Welcome to the community :wave:

Can you try changing your imports to what @Skyge suggested?

Hi @Skyge & @abcoathup, removing node_modules/ from the import solved the problem, thanks!

I’m using a truffle+react box which means I have another node_modules/ dir in the client dir. Could this have been the issue?

1 Like

Sorry, I am not familiar with the React, I think it is ok if you have two node_modules, but your folders may be like this:

--contracts
  --YourContract.sol
--node_modules      <<-- OpenZeppelin dependency should be at here
--client
  --src
  --node_modules

If I am wrong, please correct me.

1 Like

Hi @Skyge,

Absolutely right. Nice text diagram too. Thanks as always :pray:

1 Like