smartcontractkit / full-blockchain-solidity-course-py

Ultimate Solidity, Blockchain, and Smart Contract - Beginner to Expert Full Course | Python Edition
MIT License
10.67k stars 2.89k forks source link

Lesson 7: Import issue: Source "@openzeppelin/contracts/access/Ownable.sol" not found: File import callback not supported #1788

Closed emilrueh closed 1 year ago

emilrueh commented 1 year ago

I am running into an issue in Lesson 7 when importing Ownable.sol from OpenZeppelin. It seems to be the same issue as described and resolved in the topic #133 but none of the fixes have worked for me.

The error I get: Source "@openzeppelin/contracts/access/Ownable.sol" not found: File import callback not supported

I have:

(the price feed import from chainlink is working fine)

What other options do I have to debug this import issue?


My Lottery.sol file: (only the imports and skipping the rest)

// SPDX-License-Identifier: MIT

pragma solidity ^0.6.6;

import "@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract Lottery is Ownable {}

My brownie-config.yaml file: (only the dependencies)

dependencies:
  - smartcontractkit/chainlink-brownie-contracts@0.4.2
  - OpenZeppelin/openzeppelin-contracts@3.4.0
compiler:
  solc:
    remappings:
      - '@chainlink=smartcontractkit/chainlink-brownie-contracts@0.4.2'
      - '@openzeppelin=OpenZeppelin/openzeppelin-contracts@3.4.0'

EDIT: The file compiles when running brownie compile but still shows the error in the editor.

The terminal log after running compile: (skipping massive list of downloads)

Brownie v1.19.2 - Python development framework for Ethereum

1.33MiB [00:00, 2.33MiB/s]
New compatible solc version available: 0.6.12
Compiling contracts...
  Solc version: 0.6.12
  Optimizer: Enabled  Runs: 200
  EVM Version: Istanbul
Generating build data...
 - GSNRecipient
 - ...
 - etc.
 - ...
 - Strings

Compiling contracts...
  Solc version: 0.6.12
  Optimizer: Enabled  Runs: 200
  EVM Version: Istanbul        
Generating build data...
 - OpenZeppelin/openzeppelin-contracts@3.4.0/Ownable
 - OpenZeppelin/openzeppelin-contracts@3.4.0/Context
 - smartcontractkit/chainlink-brownie-contracts@0.4.2/AggregatorV3Interface
 - Lottery

Project has been compiled. Build artifacts saved at C:\Users\etc.
emilrueh commented 1 year ago

Now after struggling with it for more than an hour and reading through multiple records of similar issues with nothing working it seems to have fixed itself / been an issue with VSC not updating itself.

How it was fixed:

  1. check all points mentioned above first
  2. when everything is confirmed to be correct run: brownie compile
  3. AFTER compiling restart VSC