question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Source "@openzeppelin/contracts...." not found: File import callback not supported

See original GitHub issue

Hi all,

I need some help trying to make this extension work with the @openzeppelin/contracts NPM package. I know issues like this have been raised in the past, but I tried a lot of things and I still keep getting the same error (or similar). Here’s what I do to initialize a simple Solidity project:

mkdir ack && cd ack truffle init truffle create all DeedRepository npm init -y npm install @openzeppelin/contracts

Then I open VS Code and edit my DeedRepository contract like this,

// SPDX-License-Identifier: MIT
pragma solidity >=0.8.7;

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

contract DeedRepository is ERC721 {
  constructor(string memory _name, string memory _symbol) ERC721(_name, _symbol) {}
}

Here’s a picture where you can see both the directory structure and the code side-by-side:

image

And the ERC721.sol contract is in there as well

image

The original error

Even before trying to compile this contract, I already have an error and a warning from the extension:

image

Btw, these are my default settings. I see no mention of Solidity in there at first,

image

So I go ahead anyway and try to compile the contract by right-clicking on the screen and selecting “Solidity: Compile Contract”. This is the compiler output:

image

1st solution

I read on the Project Structure and Remappings section of the README that I should add a couple of settings. I add them so that the settings file looks like this:

image

Second error

Then I try to compile the contract again the same way as before, by right-clicking on the screen and selecting “Solidity: Compile Contract”. I get a slightly different output this time, but still no luck:

image

image

Keep in mind that the full path underlined in red on the image above actually exists on my PC.

Compiling the code through solc

I thought this might be a configuration issue with the extension itself, so I tried to compile the contract by calling solc directly

image

Reading solc docs, I see that there are a couple of arguments that I can set to tell the compiler where to look for dependencies. So I call it again and pass those arguments. It works:

image

Conclusion

I’m guessing that the values for the following settings

“solidity.packageDefaultDependenciesContractsDirectory”: “”, “solidity.packageDefaultDependenciesDirectory”: “node_modules”

eventually make their way into compiler arguments, but I can’t seem to find the appropriate values. Could someone please help me find the correct values given my project structure?

PS, compiling through the extension works if given a relative path

image

I really would like to make it work with the following import syntax, though

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

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
noyyyycommented, Oct 25, 2022

I manually add this in .vscode/setting.json and it works for me

  "solidity.remappingsUnix": ["@openzeppelin/=node_modules/@openzeppelin/"]

source: https://stackoverflow.com/a/72168392

2reactions
grumpyTofucommented, Jun 24, 2022

Not great, but the best solution I have found so far is to downgrade extension version to v0.0.135

Read more comments on GitHub >

github_iconTop Results From Across the Web

File import callback not supported"? - Smart Contracts ...
Hi, I'm following the Developing Smart Contracts "Learn" tutorial, using VSC, and all works fine but I can't seem to resolve a "problem" ......
Read more >
File import callback not supported? - solidity - Stack Overflow
The Error: Source "@openzeppelin/contracts/token/ERC20/ERC20.sol" not found: File import callback not supported enter image description here ...
Read more >
File import callback not supported error in Foundry
Try changing taking out the second. “Contracts” on the right side of the remapping. If you are using VS Code, add this to...
Read more >
ethereum/remix - Gitter
openzeppelin -contracts/contracts/access/Ownable.sol:5:1: ParserError: Source "openzeppelin-contracts/contracts/GSN/Context.sol" not found: File import ...
Read more >
Source not found: File import callback not supported
import "github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/Counters.sol"; import "github.com/OpenZeppelin/openzeppelin- ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found