2

I initalised a new truffle project by using truffle init.

I changed the solc version to ^0.6.0 in the truffle-config.js file.

I ran truffle compile and got this error:

TypeError: Error parsing C:/init-truffle/contracts/Migrations.sol: Cannot read property 'addFunction' of undefined
    at runWithReadCallback (C:\Users\Lino\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\solc\wrapper.js:37:1)
    at compileStandard (C:\Users\Lino\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\solc\wrapper.js:78:1)
    at Object.compileStandardWrapper (C:\Users\Lino\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\solc\wrapper.js:85:1)
    at Object.parseImports (C:\Users\Lino\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\truffle-compile\parser.js:47:1)
    at Object.getImports (C:\Users\Lino\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\truffle-compile\profiler.js:374:1)
    at Promise.all.then.results (C:\Users\Lino\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\truffle-compile\profiler.js:346:1)
Truffle v5.0.5 (core: 5.0.5)
Node v10.16.3

Here is the Migration.sol file:

pragma solidity >=0.4.21 <0.7.0;

contract Migrations {
  address public owner;
  uint public last_completed_migration;

  constructor() public {
    owner = msg.sender;
  }

  modifier restricted() {
    if (msg.sender == owner) _;
  }

  function setCompleted(uint completed) public restricted {
    last_completed_migration = completed;
  }
}

Here is the 1_initial_migration.js file:

const Migrations = artifacts.require("Migrations");

module.exports = function(deployer) {
  deployer.deploy(Migrations);
};

Does anyone know what to do? This file compile without any problems with solc version set to ^0.5.0.

Environment:

  • Operating System: Windows 10
  • Truffle v5.0.5 (core: 5.0.5)
  • Node v10.16.3

Thanks

  • This seems to be a problem from your JS code. please add your JS/Web3js code. – Masoud jt Jun 19 at 13:54
  • I added the only JS file automatically created by Truffle when running truffle init I modified noting more than the solidity compiler version, so there is no web3js code. – linoleparquet Jun 19 at 14:15
  • Could be an issue with Truffle which you can report at github.com/trufflesuite/truffle/issues. – Markus - soliditydeveloper.com Jun 20 at 8:11
  • Which version of truffle are you using? – rw026 Jun 22 at 10:51
2

Turn out that Truffle v5 versions earlier than v5.1.5 won't successfully compile ^0.6.0 solidity contracts, because the solc wrapper Truffle used (directly from solc-js) was only compatible with ^0.5.0 contracts.

The solution is to update the truffle package using npm update -g truffle

Thanks to CruzMolina form GitHub !

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.