Please take a look at my environment details.
Environment
- Node installed with
nvm
- Truffle is installed in different node environments which can be switched by simply changing the node by
nvm use v16.17.0
- In my vs code I have installed Truffle for VS Code extension, which is also tightly dependent on solidity extension.
- I have installed
Ganache
desktop application. - I also have
solcjs
installed asnpm
package in one of my node versions.
Contract
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.4.25 <0.9.0;
import "@openzeppelin/contracts/access/Ownable.sol";
contract CallerContract is Ownable {
}
Project Structure The node modules are installed one folder behind the truffle project for contract as shown below.
├── caller
│ ├── build
│ ├── contracts
│ ├── migrations
│ ├── test
│ └── truffle-config.js
├── oracle
│ ├── build
│ ├── contracts
│ ├── migrations
│ ├── test
│ └── truffle-config.js
├── node_modules
├── package-lock.json
├── package.json
Output
- truffle compile works fine in terminal by using
truffle compile
in all the node versions. - In VS code truffle extension's Truffle contract explorer part successfully compiles the contract.
Failure
- I am facing one failure and that is when I right-click
Solidity: Compile Contract
. It outputs
Retrieving compiler information:
Compiler using default compiler (embedded on extension), solidity version: 0.8.9+commit.e5eed63a.Emscripten.clang
ParserError: Source "@openzeppelin/contracts/access/Ownable.sol" not found: File import callback not supported
--> path to contracts/contracts/CallerContract.sol:7:1:
|
| import "@openzeppelin/contracts/access/Ownable.sol";
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Compilation failed with 1 errors
And I have tried many ways to resolve this as mentioned here, mainly this solution.
"solidity.packageDefaultDependenciesContractsDirectory": "",
"solidity.packageDefaultDependenciesDirectory": "node_modules",