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.js
中 contracts_directory
为 新增的目录 contract
module.exports = {
contracts_directory: "./contract",
contracts_build_directory: "./build",
...省略...
}
重新编译truffle compile
或者npx truffle compile
, 可以看到会连着原来目录contracts
也一起编译了,会显示具体报错信息
Truffle: TypeError: Cannot read property 'imports' of undefined
原文:https://www.cnblogs.com/buyucoder/p/14684375.html