TypeError: Cannot read property 'imports' of undefined

:computer: Environment
Visual Studio with juanblanco.solidity extension
Truffle v5.1.66 (core: 5.1.66)
Node v14.15.0
Using the latest openzeppelin contract available at “npm install @openzeppelin/contracts”

I am trying to use ERC20 to mint token however I am getting the stated error when I am trying to migrate
TypeError: Cannot read property ‘imports’ of undefined at Object. (C:\Users\dsi user\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\compile-common\dist\src\profiler\requiredSources.js:98:1)
at Generator.next ()
at fulfilled (C:\Users\dsi-user\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\compile-common\dist\src\profiler\requiredSources.js:5:42)

:1234: Code to reproduce

pragma solidity ^0.7.0;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract MyToken is ERC20 {
    constructor(uint256 initialSupply) ERC20("Gold", "GLD") {
        _mint(msg.sender, initialSupply);

For migration the code is

var MyToken = artifacts.require("MyToken.sol");
module.exports = async function (deployer) {
  await deployer.deploy(MyToken,1000000);
1 Like

Hi @rwiju,

Welcome to the community :wave:

I was able to compile your code and migrate. Can you share the command that you were running?

Truffle Compile

$ npx truffle compile

Compiling your contracts...
> Compiling ./contracts/Migrations.sol
> Compiling ./contracts/MyToken.sol
> Compiling @openzeppelin/contracts/math/SafeMath.sol
> Compiling @openzeppelin/contracts/token/ERC20/ERC20.sol
> Compiling @openzeppelin/contracts/token/ERC20/IERC20.sol
> Compiling @openzeppelin/contracts/utils/Context.sol
> Compilation warnings encountered:

    @openzeppelin/contracts/token/ERC20/ERC20.sol:55:5: Warning: Visibility for constructor is ignored. If you want the contract to be non-deployable, making it "abstract" is sufficient.
    constructor (string memory name_, string memory symbol_) public {
    ^ (Relevant source part starts here and spans across multiple lines).

> Artifacts written to /home/abcoathup/projects/forum/rwiju/build/contracts
> Compiled successfully using:
   - solc: 0.7.3+commit.9bfce1f6.Emscripten.clang


$ npx truffle develop
Truffle Develop started at

truffle(develop)> migrate

Compiling your contracts...
> Everything is up to date, there is nothing to compile.

Starting migrations...
> Network name:    'develop'
> Network id:      5777
> Block gas limit: 6721975 (0x6691b7)


   Deploying 'Migrations'


   Deploying 'MyToken'

> Total deployments:   2
> Final cost:          0.02586564 ETH

As an aside, you are currently minting less than 1 token, as the default decimals are 18.

1 Like

Hey @abcoathup ,

Thanks a lot for the welcome.

The problem has been resolved. I think the issue was with my dependencies. I reloaded them and it seems to be working fine for now

Appreciate your help


1 Like

I my case I did update two things.
One is the compiler version on my sol files to pragma solidity >=0.6.0 <0.8.0;
second update the truffle-config.js to :slight_smile:

solc: {
      version: "0.6.0",

Hi @bunker_01,
Welcome to the community :wave:

A post was split to a new topic: TypeError: Cannot read property ‘slice’ of undefined