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

Im currently using hardhat on VS code and I keep getting this error:

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

in my contract when I try and import things from openzeppelin

:1234: Code to reproduce

pragma solidity >=0.8.9;

import "@openzeppelin/contracts/token/ERC721.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/access/Ownable.sol"; 

:computer: Environment

Hardhat on vs code, openzeppelin version 4.4.1 (I think)

1 Like

Hello @revelationsz

Have you installed @openzeppelin/contracts using NPM? Is the error in vscode or when compiling with hardhat?

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

your path appears to be different from their documentation

I have a truffle project created with truffle init.
I ran the npm i @openzeppelin/contracts command, I can see the contracts in the node_modules folder.

In my contract I have an import such as:
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";

but when I do truffle compile, I get:

ParserError: Source "@openzeppelin/contracts/token/ERC721/ERC721.sol" not found
 --> project:/contracts/BossNFT.sol:4:1:
  |
4 | import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; // NFT's standard
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Truffle v5.11.5 (core: 5.11.5)
Node v18.18.0

I tried to close and reopen the project, to import everything locally. I am desperate.

This is correct. If you test that on remix it will work. I'm guessing the issue is with your truffle configuration.

Hi @Amxx,

thanks for answering.

I kind of solved the issue by, literally, moving that import over the others. It doesn't have any sense, but I guess it's a truffle problem.