Truffle: TypeError: Cannot read property 'imports' of undefined

Compiling your contracts...
===========================
TypeError: Cannot read property 'imports' of undefined
    at Object.<anonymous> (/home/vagrant/contracts/node_modules/truffle/build/webpack:/packages/compile-common/dist/src/profiler/requiredSources.js:98:1)
    at Generator.next (<anonymous>)
    at fulfilled (/home/vagrant/contracts/node_modules/truffle/build/webpack:/packages/compile-common/dist/src/profiler/requiredSources.js:5:42)
Truffle v5.3.0 (core: 5.3.0)
Node v12.14.0

有报错,但没有具体报错信息,很难定位到哪里问题。

解决方法一

使用 truffle compile --all或者npx truffle compile --all 重新编译

解决方法二

不行再试试这种,删除存放编译后文件的build目录,并重新编译

解决方法三

不行再试试这种,在合约目录同级建立一个新的目录,如原来的目录是contracts,则新增contract目录

在新目录contract中增加一个新合约Test.sol,合约内容如下

// 写个空合约就行了
pragma solidity >0.4.0;

contract Test {

}

修改truffle-config.jscontracts_directory 为 新增的目录 contract

module.exports = {
  contracts_directory: "./contract",
  contracts_build_directory: "./build",

...省略...
}

重新编译truffle compile或者npx truffle compile, 可以看到会连着原来目录contracts也一起编译了,会显示具体报错信息

issues/3798

posted @ 2021-04-21 11:02  buyuCoder  阅读(494)  评论(0编辑  收藏  举报