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

Hi, i have used the Openzeppelin Wizard to create my own NFT smart contract. (CODE BELOW).

However, i am getting the above error notification.

How do i get around this?

In another contract, i have imported the ""@openzeppelin/contracts/access/AccessControl.sol"; with the same Sol version 0.8.0 as i use the the below example, which is not throwing me any error messages..


// pragma solidity ^0.8.9;

import "@openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC721/extensions/ERC721URIStorageUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/CountersUpgradeable.sol";

contract ComNFT is Initializable, ERC721Upgradeable, ERC721URIStorageUpgradeable, PausableUpgradeable, OwnableUpgradeable, UUPSUpgradeable {
    using CountersUpgradeable for CountersUpgradeable.Counter;

    CountersUpgradeable.Counter private _tokenIdCounter;

    /// @custom:oz-upgrades-unsafe-allow constructor
    constructor() {
        _disableInitializers();
    }

    function initialize() initializer public {
        __ERC721_init("ComNFT", "CMT");
        __ERC721URIStorage_init();
        __Pausable_init();
        __Ownable_init();
        __UUPSUpgradeable_init();
    }

    function pause() public onlyOwner {
        _pause();
    }

    function unpause() public onlyOwner {
        _unpause();
    }

    function safeMint(address to, string memory uri) public onlyOwner {
        uint256 tokenId = _tokenIdCounter.current();
        _tokenIdCounter.increment();
        _safeMint(to, tokenId);
        _setTokenURI(tokenId, uri);
    }

    function _beforeTokenTransfer(address from, address to, uint256 tokenId, uint256 batchSize)
        internal
        whenNotPaused
        override
    {
        super._beforeTokenTransfer(from, to, tokenId, batchSize);
    }

    function _authorizeUpgrade(address newImplementation)
        internal
        onlyOwner
        override
    {}

    // The following functions are overrides required by Solidity.

    function _burn(uint256 tokenId)
        internal
        override(ERC721Upgradeable, ERC721URIStorageUpgradeable)
    {
        super._burn(tokenId);
    }

    function tokenURI(uint256 tokenId)
        public
        view
        override(ERC721Upgradeable, ERC721URIStorageUpgradeable)
        returns (string memory)
    {
        return super.tokenURI(tokenId);
    }
}

Can someone please advise the problem?

I have installed the openzeppelin contracts and the upgradeable contracts too.

I am using VS code

Thanks

Hi, have a try on the Remix, it can be compiled successfully, there is no errors

So maybe you can delete the file node_modules, and then reinstall to compile, and maybe there is something wrong with your VS config.

With the above imports, after reinstall, will i need to import them all separately from the github repo?

I do not think so, if you have installed the dependency in your local environment, you can import directly, just like you shared above:

import "@openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol";

Ok well this worked. Just had to uninstall and reinstall. So i did NPM CI and NPM I, plus the package import from openzeppelin and it worked.

Thanks!

1 Like