File import callback not supported

Hi,
In GSN tutorial, When compiling the Counter contract(oz compile) I got the following errors(in short):

Compiling contracts with solc 0.5.11 (commit.c082d0b4)
Compilation errors:
@openzeppelin/contracts-ethereum-package/contracts/GSN/GSNRecipient.sol:4:1: ParserError: 
Source "@openzeppelin/contracts-ethereum-package/contracts/GSN/IRelayRecipient.sol" not found: File import callback not supported
import "./IRelayRecipient.sol";
^-----------------------------^

@openzeppelin/contracts-ethereum-package/contracts/GSN/GSNRecipient.sol:5:1: ParserError: Source "@openzeppelin/contracts-ethereum-package/contracts/GSN/GSNContext.sol" not found: File import callback not supported
import "./GSNContext.sol";
^------------------------^

:computer: Environment
Windows 10 pro
node 10.16.3 and npm 6.9.0
@openzeppelin/cli@2.5.3
@openzeppelin/contracts-ethereum-package@2.2.3
@openzeppelin/upgrades@2.5.3
Truffle 5.0.25

:memo:Details
Just followed the GSN tutorials on Windows 10
I have searched similar problems of “File import callback not supported” in truffle-suite issues, but no help.

:1234: Code to reproduce
npm init -y
oz init
paste Counter.sol to contracts directory
oz compile

Any suggestion? I don’t want to add full path to import:
import “./IRelayRecipient.sol”; to import “@openzeppelin/contracts-ethereum-package/contracts/GSN/IRelayRecipient.sol”; :joy:

2 Likes

Hi @swkim109,

Welcome to the community :wave:

Which tutorial are you following?
I assume that you are using: https://docs.openzeppelin.com/sdk/2.5/gsn-dapp

Are you able to share your Counter.sol contract?

Yes, I just copy and paste:

pragma solidity ^0.5.0;

import "@openzeppelin/contracts-ethereum-package/contracts/GSN/GSNRecipient.sol";

contract Counter is GSNRecipient {
    uint256 public value;

function increase() public {
    value += 1;
}

function acceptRelayedCall(
    address relay,
    address from,
    bytes calldata encodedFunction,
    uint256 transactionFee,
    uint256 gasPrice,
    uint256 gasLimit,
    uint256 nonce,
    bytes calldata approvalData,
    uint256 maxPossibleCharge
) external view returns (uint256, bytes memory) {
    return _approveRelayedCall();
}
}

Hi @swkim109,

I haven’t been able to reproduce yet. Could you share your package.json?

I use Windows Subsystem for Linux (WSL) on Windows 10.
You may want to consider using WSL too: https://davidburela.wordpress.com/2017/05/12/how-to-install-truffle-testrpc-on-ubuntu-or-windows-10-with-windows-subsystem-for-linux/

It is OK for Linux(I tested same thing in Docker container) but still errors on Windows(can’t find files of relative path such as import “./IRelayRecipient.sol”).

I have found the similar issues in truffle suites. I guess the causes are same as this one.

This is package.json

{
  "name": "oz-gsn",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@openzeppelin/contracts-ethereum-package": "^2.2.3",
    "@openzeppelin/upgrades": "^2.5.3"
  }
}
1 Like

Hi @swkim109,

I didn’t see anything obvious in your package.json. Given that it works for you on Linux it may be Windows specific.

You may want to update to the latest version of truffle and try again as truffle is now at 5.0.35.

npm uninstall -g truffle
npm install -g truffle

Otherwise we (either you or I) can log with Truffle in case it is similar to the previous Windows issue.

I have had much fewer issues since moving to using Windows Subsystem for Linux, though it sounds like you can spin up a Linux environment when needed.

OK, Thanks.
I just wanted to do it on Windows because I usually do many things with Windows. :sweat_smile:

1 Like

Hi @swkim109,

I use Windows (except for smart contract development) :smile:

Did you get a chance to try with the latest version of truffle?
If it is still occurring we should report to Truffle as it appears to be Windows specific.

I have upgraded to Truffle 5.0.36 but same error(File import callback not supported) occurred on Windows 10.

In truffle, importing files with relative path works fine. For example, I write the ERC20 token contract:

pragma solidity ^0.5.0;

import "openzeppelin-solidity/contracts/token/ERC20/ERC20Mintable.sol";
import "openzeppelin-solidity/contracts/token/ERC20/ERC20Detailed.sol";

contract SSGToken is ERC20Mintable, ERC20Detailed("SSG Token", "SSG", 18) {

    constructor ()  public {
        mint(msg.sender, (10**9)*(10**18)); //1 billion
    }
}

ERC20Mintable.sol has

import "./ERC20.sol";
import "../../access/roles/MinterRole.sol";

truffle compile works perfect.
I doubt there is something different in oz compile and @openzeppelin/contracts-ethereum-package.

I’m using WSL now(as you suggested) and oz compile works great. :slightly_smiling_face:

1 Like

I also have this issue on Win10, following the docs learn example: https://docs.openzeppelin.com/learn/developing-smart-contracts

Edit: I changed to the wsl-ubuntu terminal, installed nvm and node, and now the npx oz compilation works fine on my project with no callback errors.

1 Like

Hi @viltiki,

I am glad you were able to resolve. I use Windows Subsystem for Linux too.

For community members coming across this, the options for Solidity Smart contract development on Windows are:

1 Like

just heads up I just filed an issue with pull request to support it without WSL since the connection in WSL is not really stable in my experience, so I still prefer use it natively. https://github.com/OpenZeppelin/openzeppelin-sdk/issues/1558

1 Like

Hi @yurenju,

Welcome to the community :wave:.

Thanks for creating the issue.

I have used WSL and now use WSL2 without issues, so sorry to hear that you have problems with it.

I definitely will try WSL2 when the upgrade rolling on my laptop :crossed_fingers:

1 Like

@abcoathup

I’m having the same Issue: Source “@openzeppelin/contracts-ethereum-package/contracts/GSN/GSNRecipient.sol” not found: File import callback not supported

with:
import “@openzeppelin/contracts-ethereum-package/contracts/GSN/GSNRecipient.sol”;

I just follow the tutorial https://docs.openzeppelin.com/learn/sending-gasless-transactions

// SPDX-License-Identifier: MIT
pragma solidity >=0.4.24 <0.7.0;

import "@openzeppelin/contracts-ethereum-package/contracts/GSN/GSNRecipient.sol";

contract Counter is GSNRecipient {
    uint256 public value;

    function increase() public {
        value += 1;
    }

    function acceptRelayedCall(
        address relay,
        address from,
        bytes calldata encodedFunction,
        uint256 transactionFee,
        uint256 gasPrice,
        uint256 gasLimit,
        uint256 nonce,
        bytes calldata approvalData,
        uint256 maxPossibleCharge
    ) external view returns (uint256, bytes memory) {
        return _approveRelayedCall();
    }

    // We won't do any pre or post processing, so leave _preRelayedCall and _postRelayedCall empty
    function _preRelayedCall(bytes memory context) internal returns (bytes32) {
    }

    function _postRelayedCall(bytes memory context, bool, uint256 actualCharge, bytes32) internal {
    }
}

The only change is with the version of solidity used. I need help, I’m using Linux, Ubuntu 18.04

1 Like

Hi @Gabriel1590,

Welcome to the community :wave:

Please see this post for how to upgrade the contract to Solidity 0.6 and use OpenZeppelin Contracts Ethereum Package v3.

Thanks, I just updated. I also solve the issue with the import by doing this way:
import "../node_modules/@openzeppelin/contracts-ethereum-package/contracts/GSN/GSNRecipient.sol";

1 Like

Hi @Gabriel1590,

Glad you are up and running.

You should be able to do import "@openzeppelin... and you shouldn’t need to have "../node_modules

it should, but gives me the same error than before

1 Like

A post was split to a new topic: File import callback not supported on MacOS