Openzeppelin contract not found in remix

Hi, i am quite new to the community and the contracts in general. The issue i am facing for a while is quite simple, but for me, quite difficult to solve. I am trying to compile my contract on remix and i have multiple errors related with importing OpenZeppelin contracts. All the errors relate with imported contracts which are ERC721.sol, Counters.sol, Ownable.sol, as i understand from the error the issue lies within the imported contracts as they are trying to import more contracts. Errors in Remix online are all the same with different contract names but i am adding an example:

ParserError: Source "@openzeppelin/contracts/utils/Context.sol" not found: Deferred import
--> @openzeppelin/contracts/access/Ownable.sol:6:1:
|
6 | import "@openzeppelin/contracts/utils/Context.sol";
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

When pressed on the error it guides me inside the imported contract and shows that there is an issue in the imported contract where it tries to import another contract. I have installed the latest OpenZeppelin library trough npm which is v4.8.2, but it doesnt seem to make a difference, I also tried different import statements, from local device and from github, tried to change the import statements in the imported contracts, still no difference..

I am also adding couple more screenshots of my contracts to have a better picture of what i am facing.


I am working on Windows and I tried Remix online, Remix Desktop, VS Code. Same issue still presists...
As i mentioned I am quite new to everything and experimenting with different things, so any help would be greatly appreciated...

Hey @Dainiuxas645, welcome :slight_smile:

This seems to be a version mismatch, the reason is that Remix downloads and caches the dependencies, so if you're using an old Remix workspace with already cached dependencies, you might experience this since the new imports are being downloaded with the latest version.

Here's the easiest solution, which is starting a Remix workspace from scratch:

An alternative might be explicitly setting the version on each import but may not work if you're using other dependency that imports OZ contracts

import "@openzeppelin/contracts@4.8.2/..."

I see your issue is still in VSCode. This shouldn't happen in a local environment, so curious to know, is it the same issue? Can you share the compilation error (if any)?

Best

Hey there @ernestognw thank you for your reply. The issue persists in VS Code as well, same compilation error as in Remix online, i tried creating new workspace on Remix online and on Remix locally also... which didn't solve the issue. Also I tried importing the contracts with different versions of OppenZeppelin (v4.8.0) but i still got same errors of "Deferred import" on all of contracts that ERC721 was importing from within.
When it comes to VS Code i am still having issues there related with import statement but slightly different: [{
"severity": 8,
"message": "Expected string literal (path), "*" or alias list.",
"startLineNumber": 6,
"startColumn": 8,
"endLineNumber": 6,
"endColumn": 26
}]

Remix states it a bit more clear for my undestading: ParserError: Source "@openzeppelin/contracts/utils/Context.sol" not found: Deferred import
--> @openzeppelin/contracts/access/Ownable.sol:6:1:
|
6 | import "../utils/Context.sol";
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Just verified creating a workspace from scratch and adding the same imports you have and it's working.

Do you have any reproducible environment/file we can test? Otherwise, I can't validate the error.
Note that VSCode is showing an import error and might not be related, although it looks like a path resolution issue, it may be to a misconfiguration on your project setup. Happens with Foundry and remappings (may be your case).

Let me know if you can share something to reproduce it :smiley:

Hi again, I am more than happy to share my whole .sol file with you directly trough the email if it would help, let me know and i would gladly share it. :wink:

2023-04-14, pn, 14:24 Ernesto García via OpenZeppelin Forum <notifications@zeppelin.discoursemail.com> rašė: