PapiBakus
PapiBakus

Reputation: 11

Source "openzeppelin-contracts/contracts/token/ERC721/ERC721.sol" not found: File import callback not supported FOUNDRY ERROR

I'm doing udemy course about solidity, and I have encounter this error in Foundry contract:

Source "openzeppelin-contracts/contracts/token/ERC721/ERC721.sol" not found: File import callback not supported

I have managed to solve this for HARDHAT and TRUFFLE by deleting "node_modules" from Juan's Blanco solidity addon in VSC but I can't do it for Foundry.

I have also tried to change workspace compilet to LocalFile, or NodeModule as per other posts in here but nothing worked.

Just to be clear, everything compiled correctly but still get this error which is kinda annoying.

Any ideas?

Upvotes: 1

Views: 2063

Answers (5)

salah-1
salah-1

Reputation: 1399

For this specific error you can fix by installing dependency via forge or npm and that will populate your /lib dir. From the commandline do:

forge install OpenZeppelin/openzeppelin-contracts

for js/node codebase, below:

npm install @openzeppelin/contracts

docs:

Upvotes: 0

jon.bray.eth
jon.bray.eth

Reputation: 617

install dependencies

You can install dependencies in Foundry from a GitHub repo by using:

forge install <repo-url>.git --no-commit

this will place the dependency repo inside of the lib/ directory in your project

remappings

once you have the dependency installed you need to ensure that you have remappings set up so that Foundry knows how to associate an import statement in your contract with a dependency, this can be done one of two ways...

first, directly inside of the foundry.toml file:

remappings = [
    "forge-std/=lib/forge-std/src/",
    "openzeppelin/=lib/openzeppelin-contracts/",
    ...
    ...
]

or inside of a remappings.txt file:

forge-std/=lib/forge-std/src/
openzeppelin/=lib/openzeppelin-contracts/
uniswap/v2-core/=lib/v2-core/
...
...

this will associate import "openzeppelin/contracts... with the correct local path of lib/openzeppelin-contracts/contracts...

if you get a build error that nested dependencies are also not found, ensure you have @openzeppelin/=lib/openzeppelin-contracts/ in your remappings.

tl;dr

  1. install dependencies with forge install...
  2. point remappings to local dependency

Upvotes: 2

Satoshi Naoki
Satoshi Naoki

Reputation: 393

you need to add openzeppelin-contracts as a git submodule first

[submodule "lib/openzeppelin-contracts"]
    path = lib/openzeppelin-contracts
    url = https://github.com/openzeppelin/openzeppelin-contracts 

then, you need to do remapping(in remappings.txt)

openzeppelin/=lib/openzeppelin-contracts/

Upvotes: 0

Triple Nine
Triple Nine

Reputation: 1

the solution is simple. I had the same issue and couldn't find a way around it. You have to re-install Solidity extension from Juan Blanco and install v. 0.0.135. Then reload.

Upvotes: 0

Mikko Ohtamaa
Mikko Ohtamaa

Reputation: 83656

Because you are using an external dependency you need to

As your question lacks details, it is not possible to tell which of these steps you have done and which solutions you have attempted so far.

Upvotes: 1

Related Questions