'File import callback not supported?
Tried to run:
1.) Dappuniversity project (dappuniversity/dbank) 2.) pet-shop-tutorial
Truffle v5.3.3 (core: 5.3.3) Node v14.15.5
How can ser compile code @ the 0.8.4 to import OpenZeppelin’s ERC20.sol template, when Truffle requires it’s compiler/solc to match 5.3.3?
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract Token is ERC20 {
//add minter variable
//add minter changed event
constructor() public payable ERC20("Name", "Symbol") {
//assign initial minter
}
//Add pass minter role function
function mint(address account, uint256 amount) public {
//check if msg.sender has a minter role
_mint(account, amount);
}
}
Source “@openzeppelin/contracts/token/ERC20/ERC20.sol” not found: File import callback not supported
Solution 1:[1]
The Error: Source "@openzeppelin/contracts/token/ERC20/ERC20.sol" not found: File import callback not supported

Step 1:
Install the Solidity Extention

Step 2:
Step 3:
Solution 2:[2]
For me (running Win 10) this error resolved when I cleared out a setting in the VSCode solidity extension.
Extensions menu
--> Right click Solidity by Juan Blanco
--> Extension Settings
--> Scroll to "Solidity:Package Default Dependencies Contracts Directory"
--> Delete the default value
The default value was pointing things to the wrong path.
https://github.com/juanfranblanco/vscode-solidity/issues/178
Solution 3:[3]
Install any missing dependencies and add them to your package.json.
Note that some packages, like @chainlink/contracts require using yarn, because they use yarn workspaces.
npm ERR! Error: Please use yarn to install dependencies
for example:
yarn add @chainlink/contracts
However, I did not make it work for packages that include @version tag, because the import path does not match any folder in node_modules.
npm i @openzeppelin/[email protected]
The error went away when I removed the version from the path, but I don't know how legit this is.
It does still compile though ¯\(?)/¯
Solution 4:[4]
I am running hardhat in a yarn package, under packages/. To eliminate this error, go to the preferences for the Solidity plugin.
Preference: Package Default Dependencies Directory
Value: packages/hardhat/node_modules
Solution 5:[5]
If the node_modules directory that contains the script you want to import is not at the root of your VSCode workspace, you can point the solidity extension to it manually in .vscode/settings.json like so:
{
"solidity.packageDefaultDependenciesDirectory": "path/to/sub/dir/node_modules"
}
Solution 6:[6]
A simple hack to this would be import from the absolute path of the module.
Something like import "/yourApp/node_modules/@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol" in your .sol file! This is hassle free and works 100% :)
Though the above will remove the error from VSCODE but when you will compile the contract it will throw errors. So it would be better to be with the VSCODE error and get the contract compiled and deployed without errors!! :D
Solution 7:[7]
ERC20 file requires other files
pragma solidity ^0.8.0;
import "./IERC20.sol";
import "./extensions/IERC20Metadata.sol";
import "../../utils/Context.sol";
it is not clear if you have correctly installed OpenZeppelin or not.
Solution 8:[8]
If you are using VSCODE solidity extension: make sure you are running VSCODE from the directory below /contracts/ and /node_modules/ where the package.json lives.
Paths will be updated and the errors will go away.
Solution 9:[9]
Create a folder .vscode in your root folder and then create a file settings.json inside .vscode with the following content. Ensure the path is correct:
{
"solidity.remappings":["@openzeppelin/=/Users/john/workspace/myproject/smart_contract/node_modules/@openzeppelin"]
}
Solution 10:[10]
Before trying anything, in case any of you copied the entire contract from a tutorial, first try changing the contract 'Name'. For me, I noticed I still had the original contract name here, and once I changed it to MY project (contract) name, then error went away. Worth a shot before tinkering with the extension settings:
E.g. Instead of:
contract OriginalTutorialContractName is ERC721, Ownable {
make sure to update for your project:
contract YourContractNameHere is ERC721, Ownable {
Solution 11:[11]
I am on Linux working with a truffle project. I passed the relative path even though node_modules is automatically set as the Package Default Dependencies Contracts Directory setting of the solidity extension:
import "../node_modules/@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "../node_modules/@openzeppelin/contracts/utils/Counters.sol";
Solution 12:[12]
If you're using VSCode, this error is caused when your IDE fails to resolve the import paths.
Some contract packages contain contracts in the contracts folder, whereas others may contain subfolders containing contracts folders in them, and this causes path errors.
If you're using Solidity extension by Juan, make sure you have your remappings correct:
This is an example of the settings.json file that would pop up if you choose to modify the remappings. Note that the remapping template is: NAME_OF_PACKAGE/=node_modules/PATH_TO_PACKAGE:
{
...,
"solidity.remappingsUnix": [
"@uniswap/=node_modules/@uniswap/",
"@openzeppelin/=node_modules/@openzeppelin/"
]
}
Solution 13:[13]
For me, the following worked
Under solidity plugin settings on vs code(I'm on mac), I made sure that node_modules is removed from Solidity: Package Default Dependencies Directory box.
As soon as I remove this, the error goes away.
If I add node_modules back in that box, the error comes again.
PS: I am assuming that in your repo directory, you have already installed openzeppelin correctly
npm install @openzeppelin/contracts
Solution 14:[14]
The error is caused by the solc-js compiler. The GitHub page is https://github.com/ethereum/solc-js
You need to compile with an import callback, I do not know how Truffle handles this, but in case you were compiling yourself programmatically, you would have to use an import callback as in the following code (example taken from the GitHub page, the findImports function changed to how it is working for me):
const solc = require('solc');
const input = {
language: 'Solidity',
sources: {
'test.sol': {
content: 'import "lib.sol"; contract C { function f() public {
L.f(); } }'
}
},
settings: {
outputSelection: {
'*': {
'*': ['*']
}
}
}
};
function findImports(relativePath) {
//my imported sources are stored under the node_modules folder!
const absolutePath = path.resolve(__dirname, 'node_modules', relativePath);
const source = fs.readFileSync(absolutePath, 'utf8');
return { contents: source };
}
// New syntax (supported from 0.5.12, mandatory from 0.6.0)
var output = JSON.parse(
solc.compile(JSON.stringify(input), { import: findImports })
);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow





