Truffle: File import callback not supported

Created on 30 Sep 2017  路  24Comments  路  Source: trufflesuite/truffle

  • [x] I've asked for help in the Truffle Gitter before filing this issue.

Issue

Attempting to import a dependency of a contract from a node module fails.

Steps to Reproduce

Can reproduce with the following script in a fresh directory

#!/bin/bash
truffle init
npm install --save zeppelin-solidity
ed contracts/MetaCoin.sol <<EOED
3a
import "node_modules/zeppelin-solidity/contracts/lifecycle/Pausable.sol";
.
wq
EOED

testrpc -d &
sleep 5
truffle compile

Expected Behavior

Expect contract to compile.

Actual Results

Compilation fails with the following output:

Compiling ./contracts/ConvertLib.sol...
Compiling ./contracts/MetaCoin.sol...
Compiling ./contracts/Migrations.sol...
Compiling ./node_modules/zeppelin-solidity/contracts/ownership/Ownable.sol...
Compiling node_modules/zeppelin-solidity/contracts/lifecycle/Pausable.sol...

node_modules/zeppelin-solidity/contracts/lifecycle/Pausable.sol:4:1: ParserError: Source "node_modules/zeppelin-solidity/contracts/ownership/Ownable.sol" not found: File import callback not supported
import "../ownership/Ownable.sol";
^--------------------------------^
Compiliation failed. See above.

Environment

  • Operating System: Ubuntu 16.04.3
  • Truffle version: 3.4.11
  • Ethereum client: testrpc
  • node version: 8.5.0
  • npm version: 5.4.2
stale

Most helpful comment

I had the same issue as @evgen-povt and after deleting the build/ folder it worked.
There is an bug somewhere. could it be some caching issues ?

All 24 comments

Ditto on the above

the same error. Has anybody managed to solve the problem?

try to use relative path for imports. node_modules/zeppelin-solidity => ../node_modules/zeppelin-solidity

It's is not a path issue.

If the path is wrong it prints:
Error: Could not find <path>/<filename1>.sol from any sources; imported from <path>/<filename2>.sol

But actual error is:
<filename2>.sol:6:1: ParserError: Source "<filename1>.sol" not found: File import callback not supported

@evgen-povt, did you try it? it works for me

Actually I have the problem with a contract placed in the same directory, not a zeppelin contract.

Yes, I tried to
import '../contracts/<filename1>.sol'
and had the same error.

If I try:
import '../<filename1>.sol'
the error is
Error: Could not find <path>/<filename1>.sol

@mcdee - @ByKraB is correct, you could resolve this by using a relative path to the zeppelin-solidity contracts in node_modules. You should also be able to use this form:

import "zeppelin-solidity/contracts/ownership/Ownable.sol";

@evgen-povt: Out of curiosity:

  • where is the file which contains the import statement?
  • where is the file you're trying to import?

both files are in the same directory 'contracts'.

The most weird thing is that the being imported file is imported in the another contract successfully.

@evgen-povt Could you see if importing like this works?

import "./<filename>.sol";

That is exactly how I import the file.

@evgen-povt Is it possible there is a typo in the import statement somewhere, perhaps a letter that should be capitalized? Could you look at it carefully or reproduce exactly what the statements are here? The fact that it works for one file and not the other suggests something might be wrong with the one it doesn't work for.

I rechecked it many times.

I have tried to copy-paste the import statement.
I have even try to import another contract from the same directory and it gave me the same error.

@evgen-povt Apologies but I'm unable to reproduce this using the default Truffle project metacoin on Truffle 4.0.5. I ran truffle unbox metacoin. Then added two simple contracts to the contracts folder:

AnotherImport.sol
AnotherImport2.sol

Then I imported them into MetaCoin.sol as below:

import "./ConvertLib.sol";
import "./AnotherImport.sol";
import "./AnotherImport2.sol";

Then I invoked the imports via new in the MetaCoin constructor as below:

function MetaCoin() public {
    balances[tx.origin] = 10000;
    address a = new AnotherImport();
    address b = new AnotherImport2();
}

Then ran truffle test. Everything works as expected.

@evgen-povt Please link to a working project that provides a minimal example of the error. Closing this for now because the original poster's issue seems resolvable given the information they provided.

[EDIT] @evgen-povt Please feel free to open a separate issue with reproducible steps and I will happily look into it. Thanks!

I had the same issue as @evgen-povt and after deleting the build/ folder it worked.
There is an bug somewhere. could it be some caching issues ?

@wighawag Do you have a reproduction step? Also could you report your truffle version?

Will happily re-open this if we can verify it's happening again - would really like to squash any bugs here.

Since I deleted my build folder, I cannot reproduce now. If I or someone else get it back, publishing the build folder might help reproduce it.

I had experienced the issue event after cleaning the build directory.

On updating to Truffle v4.1.11 the issue has gone.

@cgewecke
I bumped into the issue again.
I added more logs in the file solc-js/wrapper.js
and found out that the variable solcStandardInput.sources from truffle-compile/index.js contained a duplicates.
The first record had the absolute path and compiled successfully.
And the second one had a relative path - here the compilation failed.

I temporary fixed solc-js to search relative paths in absolute paths and it started working.

So the bug is definitely how the list of files is collected and passed to the compiler.

@evgen-povt Thanks for pinging this. What version of truffle are you using? Is there any way you can give me a way to reproduce this duplicates relative/absolute case? I'd really like to make sure that's not happening.

@cgewecke I have found out the issue. It was on my side.

Here is my situation:
I have 3 contracts: A, B and C.
A imports B, and B imports C.
But there was small issue: A imported B as
import "contracts/B"
instead of
import "./B"

Although A was compiled successfully the compilation failed on the contract B with message that the B couldn't import C.

The only issue of Truffle is: why does it allows (and even compiles) to make import with incorrect paths?

@wighawag deleting the build folder solved the problem for me! thank you.

Thank you for raising this issue! It has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. If you would like to keep this issue open, please respond with information about the current state of this problem.

There has been no new activity on this issue since it was marked as stale 7 days ago, so it is being automatically closed. If you'd like help with this or a different problem, please open a new issue. Thanks!

try to use relative path for imports. node_modules/zeppelin-solidity => ../node_modules/zeppelin-solidity

This also works for me. THX!!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ripper234 picture ripper234  路  4Comments

rotcivegaf picture rotcivegaf  路  3Comments

jleeh picture jleeh  路  3Comments

timothywangdev picture timothywangdev  路  3Comments

rjl493456442 picture rjl493456442  路  4Comments