trufflesuite / truffle-migrate

On-chain migrations management
17 stars 17 forks source link

migrations fail when setting non-standard contracts_build_directory #10

Closed chapati23 closed 5 years ago

chapati23 commented 7 years ago

Description

I need a custom build directory so I set contracts_build_directory to src/contracts in the truffle.js config file. This worked fine for truffle compile => my compiled contracts ended up in src/contracts as expected.

Error

However when I tried running truffle migrate it failed with the following error:

Using network 'development'.

Running migration: 1_initial_migration.js
/Users/chapati/.nvm/versions/node/v8.1.4/lib/node_modules/truffle/build/cli.bundled.js:36916
  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 (/Users/chapati/.nvm/versions/node/v8.1.4/lib/node_modules/truffle/build/cli.bundled.js:36916:9)
    at ResolverIntercept.require (/Users/chapati/.nvm/versions/node/v8.1.4/lib/node_modules/truffle/build/cli.bundled.js:219315:32)
    at /Users/chapati/projects/brickblock/react-box/migrations/1_initial_migration.js:1:28
    at ContextifyScript.Script.runInContext (vm.js:53:29)
    at ContextifyScript.Script.runInNewContext (vm.js:59:15)
    at /Users/chapati/.nvm/versions/node/v8.1.4/lib/node_modules/truffle/build/cli.bundled.js:83185:14
    at tryToString (fs.js:512:3)
    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:500:12)

Question

Anything else I need to configure when changing the contracts_build_directory that I'm overlooking? Stabbing a bit in the dark here as the custom-build options aren't very well documented yet.

szerintedmi commented 7 years ago

I'm having the same issue :/ I've tried to play with working_directory and migrations_directory in truffle.js too but no luck. Migration fails on this line: var Migrations = artifacts.require("./Migrations.sol"); error for me:

$ truffle migrate
Using network 'development'.

Running migration: 1_initial_migration.js
/usr/local/lib/node_modules/truffle/build/cli.bundled.js:49085
  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/lib/node_modules/truffle/build/cli.bundled.js:49085:9)
    at Object.require (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:72130:36)
    at ResolverIntercept.require (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:228716:32)
    at /Users/petro/ether/ucd-poc/migrations/1_initial_migration.js:1:28
    at ContextifyScript.Script.runInContext (vm.js:53:29)
    at ContextifyScript.Script.runInNewContext (vm.js:59:15)
    at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:99900:14
    at tryToString (fs.js:512:3)
    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:500:12)

When look to ResolverIntercept.require (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:228716:32) there is a simple line:

  // Note, will error if nothing is found.
  var resolved = this.resolver.require(import_path);

There I gave up tracing which module called with what import_path value :/

DmitryRomaniuk commented 7 years ago

In my case, I had mistake in contract name. Contract name should same name as the .sol file name.

szerintedmi commented 7 years ago

@DmitryRomaniuk : do you mean it works for you with a custom build folder?

chapati23 commented 7 years ago

btw my workaround currently is leaving the original folder structure in place and creating symlinks => works well so far

Sent from my iPhone

On Aug 14, 2017, at 08:59, Peter Petrovics notifications@github.com wrote:

@DmitryRomaniuk : do you mean it works for you with a custom build folder?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

szerintedmi commented 7 years ago

unfortunately symlinks aren't trivial for us b/c of mixed windows and linux dev environments :/

chapati23 commented 7 years ago

yeah it's a hack. should definitely be fixed in truffle

chapati23 commented 7 years ago

here's our latest workaround, now without symlinks so should work across systems @szerintedmi


// package.json
{
    …
    // Compile smart contracts and copy output into src/ and build/ folders
    "build:contracts": "truffle compile && yarn contracts:sync-src",

    // Workaround to use custom build directories until this issue gets resolved: https://github.com/trufflesuite/truffle-migrate/issues/10
    "contracts:sync-src": "rimraf src/contracts && cp -R build/contracts/ src/contracts",
    …
}
ltfschoen commented 6 years ago

I got the error because I had explicitly stated the contract build directory in my truffle.js file with `contracts_build_directory: "./build",, even though it uses the build/ directory by default anyway:

module.exports = {
  contracts_build_directory: "build",
  networks: {
    development: {
      host: "127.0.0.1",
      port: 8545,
      network_id: "*"
    }
  }
};

After I removed that line of code so it became the following, the error message went away.

module.exports = {
  networks: {
    development: {
      host: "127.0.0.1",
      port: 8545,
      network_id: "*"
    }
  }
};
lennartkramer1988 commented 6 years ago

Was on a windows machine and ran into some problems, below is a changed sync-src script command for windows.

Based on workaround posted by @chapati23

    "contracts:sync-src": "rimraf src\\contracts\\* && xcopy build\\contracts src\\contracts /F /Y"

ps: assumes that src/contracts folder exists.

gre commented 6 years ago

I can experience the issue as well. contracts_build_directory is broken basically. makes me think truffle deploy must have hardcoded a lookup into build folder or don't even read that option

ngan commented 6 years ago

Experiencing this as well. The problem happens when setting either contracts_build_directory or build_directory. What's weirder is even when you set it them to the default values:

build_directory: "build",
contracts_build_directory: "build/contracts",

The error still happens.

helxsz commented 6 years ago

having the same issue when setting contracts_build_directory

kushan-gunasekera commented 6 years ago

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

That's it.

qapquiz commented 6 years ago

I have some workaround for this case. The solution is you have to use fullpath for the build directory in truffle.js.

// truffle.js
const fullPathBuildDirectory = `${__dirname}/src/build/contracts`;

module.exports = {
  contracts_build_directory: fullPathBuildDirectory,
  networks: {
    ...
  }
}; 

something like this will solve the issue.

rogargon commented 6 years ago

Has this issue been open for a year without a solution?

zhengwanzhang commented 6 years ago

Truffle has a lot of problems.GIVE UP.

SvenMeyer commented 6 years ago

The solution from @qapquiz above solved it for me! https://github.com/trufflesuite/truffle-migrate/issues/10#issuecomment-402441008

It looks like as if you need to keep (a copy of) Migrations.json in build/contracts, otherwise you will get an an error like

Error: Attempting to run transaction which calls a contract function, but recipient address 0x8cdaf0cd259887258bc13a92c0a6da92698644c0 is not a contract address

But as Migrations.sol / Migrations.json normally never change, this is just a one time action during project setup and thus should not be too much of an issue.

CruzMolina commented 5 years ago

Thanks for raising this issue @chapati23!

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