Truffle: Could not find artifacts for ./Migrations.sol from any sources

Created on 19 Dec 2017  路  9Comments  路  Source: trufflesuite/truffle

  • [ ] I've asked for help in the Truffle Gitter before filing this issue.

Issue

when execute "truffle migrate --network dev"
get this:
Could not find artifacts for ./Migrations.sol from any sources

Steps to Reproduce

truffle.js
module.exports = {
  // See <http://truffleframework.com/docs/advanced/configuration>
  // to customize your Truffle configuration!
  contracts_build_directory: "./build",
  networks: {
    dev: {
      host: "localhost",
      port: 9545,
      network_id: "*",
    }
  }
};
  1. truffle unbox metacoin
  2. truffle compile
  3. truffle migrate --network dev

Expected Behavior

Using network 'dev'.

Network up to date.

Actual Results

Using network 'dev'.

Running migration: 1_initial_migration.js
/usr/local/nodejs/lib/node_modules/truffle/build/cli.bundled.js:63556
throw new Error("Could not find artifacts for " + import_path + " from any sources");
^

Error: Could not find artifacts for ./Migrations.sol from any sources
at Resolver.require (/usr/local/nodejs/lib/node_modules/truffle/build/cli.bundled.js:63556:9)
at Object.require (/usr/local/nodejs/lib/node_modules/truffle/build/cli.bundled.js:176187:36)
at ResolverIntercept.require (/usr/local/nodejs/lib/node_modules/truffle/build/cli.bundled.js:324348:32)
at /home/leo/Documents/src_codes/dapp/demo/migrations/1_initial_migration.js:1:28
at ContextifyScript.Script.runInContext (vm.js:59:29)
at ContextifyScript.Script.runInNewContext (vm.js:65:15)
at /usr/local/nodejs/lib/node_modules/truffle/build/cli.bundled.js:203486:14
at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:511:3)

Environment

  • Operating System: ubuntu 16.04
  • Truffle version: 4.0.3
  • Ethereum client: geth
  • node version: 8.9.3
  • npm version: 5.6.0

Most helpful comment

I got the same problem just now, but I solved it in this way.

  • After your compilation, go to your_folder_location\build\contracts folder.

  • Then you will see a JSON file which not related to your contract file.

  • Just rename that JSON file same as your contract file. ( most probably that JSON file related your folder name )

  • But after that you can see the renamed file as well as the original file too, both files in same location. Don't worry.

That's it.

All 9 comments

if i delete the "2_deploy_contracts.js" and compile and migrate again, it will be ok.

I had similar problem. Solved it by editing 2_deploy_contracts.js to require and deploy the exact contracts I had written.

It may be related to this issue 552

Make sure you named your test as Test + contract name

So if you have a contracts/SECToken.sol
Make sure you test named tests/TestSECToken.sol

and I guess you have name your contract SECToken too

I got the same problem just now, but I solved it in this way.

  • After your compilation, go to your_folder_location\build\contracts folder.

  • Then you will see a JSON file which not related to your contract file.

  • Just rename that JSON file same as your contract file. ( most probably that JSON file related your folder name )

  • But after that you can see the renamed file as well as the original file too, both files in same location. Don't worry.

That's it.

Thanks for raising this issue @leochan007!

We've finally merged a fix for this into truffle@next via #1331.

I got the same problem just now, but I solved it in this way.

* After your compilation, go to `your_folder_location\build\contracts` folder.

* Then you will see a JSON file which not related to your contract file.

* Just rename that JSON file same as your contract file. ( most probably that JSON file related your folder name )

* But after that you can see the renamed file as well as the original file too, both files in same location. Don't worry.

That's it.

I had a similar problem and I looked into it I got to know that truffle compile compiles the .sol file and generate new JSON file in build folder ./build/contracts/<name_of_contract_in_.sol_file>.json and this JSON file has the name of the contract not the name of .sol file.

Example

I create a test.sol file.

pragma solidity ^0.5.0;

contract MyContract {

    uint id;

    function set(uint _id) public {
        id = _id;
    }
}

and now if I truffle compile it I will have ./build/contracts/MyContract.json

and that was the problem for me all along was in 2_deploy_contracts.js file I was doing require the name of the .sol file say it test.sol for the sake of the example here but I had the same name for both contract and filename of .sol file but after looking into it I got to know that my contract name had a one extra letter it was misspelled and that's why I got the error.

so by having same name for contract and its filename solved the problem for me.

I got the same problem just now, but I solved it in this way.

* After your compilation, go to `your_folder_location\build\contracts` folder.

* Then you will see a JSON file which not related to your contract file.

* Just rename that JSON file same as your contract file. ( most probably that JSON file related your folder name )

* But after that you can see the renamed file as well as the original file too, both files in same location. Don't worry.

That's it.

Worked.
To avoid this issue, make sure your contract's and the contract file has the same name:
ie:
"pragma solidity 0.5.12;

contract Token20 {
...
"
in file named Token20.sol

Simply turn on 'Auto Save' on your VS Code. That is the issue . Solved after that.

Was this page helpful?
0 / 5 - 0 ratings