ParserError when importing OpenZeppelin Contracts in VSCode

:computer: Environment

@openzeppelin/contracts”: “^3.3.0”,
“solc”: “^0.7.0”,


Whenever I try to compile my contract with imported openzeppelin contracts I get an error:
ParserError: Source \"@openzeppelin/contracts/token/ERC20/ERC20.sol\" not found: File import callback not supported\nimport \"@openzeppelin/contracts/token/ERC20/ERC20.sol\

:1234: Code to reproduce

pragma solidity ^0.7.0;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

import "@openzeppelin/contracts/math/SafeMath.sol";

contract SMPTokenSale {
1 Like

Hi @Alien_Lobster,

What tool are you using to compile your project?

If you are using Juan Blanco’s Solidity plugin, then the default behavior should pickup OpenZeppelin Contracts in node_modules, see:

I am using Juan Blanco’s Solidity plugin. I think I’ve resolved this by defining the path to the imports in my compile.js:

 const path = require("path");
const fs = require("fs-extra");
const solc = require("solc");
const resolvePath = require("./path-resolve");
const buildPath = path.resolve(__dirname, "build");

// All files imported in the contract
const paths = resolvePath({
  "ERC20.sol": "../node_modules/@openzeppelin/contracts/token/ERC20/ERC20.sol",
  "GSN/Context.sol": "../node_modules/@openzeppelin/contracts/GSN/Context.sol",

const tokenSalePath = path.resolve(__dirname, "contracts", "SMPTokenSale.sol");
const smpTokenSale = fs.readFileSync(tokenSalePath, "utf-8");

const input = {
  language: "Solidity",
  sources: {
    "SMPTokenSale.sol": {
      content: smpTokenSale,
  settings: {
    outputSelection: {
      "*": {
        "*": ["*"],

function findImports(path) {
  if (paths[path]) return { contents: paths[path] };
  else return { error: "File not found" };

const output = JSON.parse(
  solc.compile(JSON.stringify(input), { import: findImports })


for (let contract in output) {
    path.resolve(buildPath, contract.replace(":", "") + ".json"),


This seemed to have resolved the errors.

1 Like