Truffle compiler option 'contracts_build_directory' inconsistent behavior
See original GitHub issueTruffle compiler option contracts_build_directory is described here.
I’m having trouble with Truffle’s inconsistent behavior on that configuration parameter.
I’m setting it as follows:
contracts_build_directory: "../../artifacts"
When I execute truffle compile, all artifacts are created in a folder named “artifacts” which is located two levels above the project’s root directory.
When I execute truffle migrate --network=development, I get the following error message:
Running migration: 1_initial_migration.js
fs.js:904
return binding.readdir(pathModule._makeLong(path), options.encoding);
^
Error: ENOENT: no such file or directory, scandir '<see_below>\artifacts'
Where <see_below> is a full path which ends only one level above the project’s root directory.
I can therefore resolve this problem as follows:
- Run
truffle compile - Change
contracts_build_directoryfrom"../../artifacts"to"../../../artifacts" - Run
truffle migrate --network=development
This solution is inappropriate of course.
My project directory structure is as follows:
project folder:
contracts folder:
sol files
migrations folder:
1_initial_migration.js file
2_deploy_contracts.js file
test folder:
js files
truffle-config.js file
My truffle configuration (in truffle-config.js) is as follows:
// See <http://truffleframework.com/docs/advanced/configuration>
module.exports = {
contracts_build_directory: "../../artifacts",
networks: {
development: {
host: "127.0.0.1",
network_id: "*",
port: 8545,
gas: 4712388, // Gas limit used for deploys
gasPrice: 100000000000, // Gas price used for deploys
},
},
mocha: {
useColors: true,
bail: true, // Abort after first test failure
reporter: "list", // See <https://mochajs.org/#reporters>
},
solc: {
optimizer: {
enabled: true,
runs: 5000000,
},
},
};
To my understanding, the problem stems from the fact that truffle migrate “steps into” the migrations folder and runs from there (hence an additional ..\ is required in the value of the contracts_build_directory parameter).
UPDATE:
If I delete all the artifacts, and then run truffle migrate without preceding it with truffle compile (i.e., letting truffle migrate do the compilation), then it works only when the contracts_build_directory option is NOT specified. Any other way (even setting it to the default value ./build/contracts or to the “trivial” value ./) - the migration fails.
So in short, there seem to be a “collision” between truffle migrate and contracts_build_directory.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:3
- Comments:15 (3 by maintainers)

Top Related StackOverflow Question
I got problem at
return binding.readdir(pathModule.toNamespacedPath(path), options.encoding)instead. I’m on Linux buttoNamespacedPathseems to only work on Windows, might this be a problem with OS detection? I’m using Arch.I found a workaround:
I have get the problem like this. So How to set directory?