首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >编译错误:无法读取属性.未定义的

编译错误:无法读取属性.未定义的
EN

Ethereum用户
提问于 2020-06-19 13:24:54
回答 1查看 6.2K关注 0票数 4

我使用truffle init开发了一个新的松露项目。

我将松露-config.js文件中的solc版本更改为^0.6.0。

我运行了truffle compile并得到了以下错误:

代码语言:javascript
复制
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

下面是Migration.sol文件:

代码语言:javascript
复制
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;
  }
}

下面是1_initial_migration.js文件:

代码语言:javascript
复制
const Migrations = artifacts.require("Migrations");

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

有人知道该怎么做吗?此文件编译时,solc版本设置为^0.5.0,没有任何问题。

环境:

  • 操作系统: Windows 10
  • 松露v5.0.5 (核心: 5.0.5)
  • 节点v10.16.3

谢谢

EN

回答 1

Ethereum用户

发布于 2020-06-22 16:40:59

结果表明,Truffle v5版本早于v5.1.5,不会成功编译^0.6.0稳固协议,因为所使用的solc包装器(直接来自solc)只与^0.5.0契约兼容。

解决方案是使用npm update -g truffle更新块菌包。

感谢CruzMolina来自GitHub!

票数 8
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/84388

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档