Truffle搭建环境migrate步骤错误解决方案

1.truffle migrate失败

报错信息为:

2_deploy_contracts.js
=====================

C:\Users\asus\AppData\Roaming\npm\node_modules\truffle\build\cli.bundled.js:260211
  throw new Error("Could not find artifacts for " + import_path + " from any sources");
        ^
C:\Users\asus\AppData\Roaming\npm\node_modules\truffle\build\cli.bundled.js:260211
  throw new Error("Could not find artifacts for " + import_path + " from any sources");
  ^

Error: Could not find artifacts for MetaCoin from any sources
    at Resolver.require (C:\Users\asus\AppData\Roaming\npm\node_modules\truffle\build\cli.bundled.js:260211:9)
    at Object.require (C:\Users\asus\AppData\Roaming\npm\node_modules\truffle\build\cli.bundled.js:421918:38)
    at ResolverIntercept.require (C:\Users\asus\AppData\Roaming\npm\node_modules\truffle\build\cli.bundled.js:628274:32)
    at C:\Users\asus\Desktop\dapp\migrations\2_deploy_contracts.js:2:26
    at ContextifyScript.Script.runInContext (vm.js:59:29)
    at ContextifyScript.Script.runInNewContext (vm.js:65:15)
    at C:\Users\asus\AppData\Roaming\npm\node_modules\truffle\build\cli.bundled.js:470837:14
    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:511:3)

报错信息的意思是找不到该合约的位置,所以无法执行deploy操作

2.解决方案

我查阅过很多个博客都没有好的解决方案,于是在自己探索的情况下找到解决方案。

在2_deploy_contracts.js文件中,将require里面的参数改成你的合约名字,

而不是sol文件名字,即不必sol后缀,这一点比较坑!!!

Truffle搭建环境migrate步骤错误解决方案_第1张图片

这里可以看到编译后的合约名字。

//var ConvertLib = artifacts.require('./ConvertLib.sol')
var Test = artifacts.require('./Test')
//var Test = artifacts.require('.Test.sol')

module.exports = function (deployer) {
  //deployer.deploy(ConvertLib)
  //deployer.link(ConvertLib, MetaCoin)
  deployer.deploy(Test)
}

成功截图:
Truffle搭建环境migrate步骤错误解决方案_第2张图片

3. migrate显示未打开网络

Error: No network specified. Cannot determine current network.

    at Object.detect (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:41338:23)

    at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:202239:19

    at finished (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:41266:9)

    at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:200593:14

    at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:63299:7

    at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:165077:9

    at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:161676:16

    at replenish (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:162196:25)

    at iterateeCallback (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:162186:17)

    at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:162161:16

4.解决方案

修改文件目录下的truffle-config.js配置为以下

// Allows us to use ES6 in our migrations and tests.
require('babel-register')
module.exports = {
networks: {
        development: {
            host: "localhost",
            port: 8545,
            network_id: "*" // 匹配任何network id
         }
    }
};

你可能感兴趣的:(Truffle,migrate错误,depoloy失败,Blockchain)