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”
Details
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)
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
Migrate
$ npx truffle develop
Truffle Develop started at http://127.0.0.1:9545/
...
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)
1_initial_migration.js
======================
Deploying 'Migrations'
----------------------
...
2_deploy.js
===========
Deploying 'MyToken'
-------------------
...
Summary
=======
> 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.
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