24

Truffle configuration file is mentioned in several places on the web (GitHub, truffle package on npm, solidity-coverage package on npm, etc.).

Some refer to it as 'truffle.js, others refer to it as truffle-config.js.

When creating a project with truffle init, both files are created.

Which one of them should I use?

Thank you.

Shane Fontaine
  • 18,036
  • 20
  • 54
  • 82
goodvibration
  • 26,003
  • 5
  • 46
  • 86
  • truffle.js was used in earlier versions of truffle i.e. 4 and below. Latest version uses truffle-config.js see https://www.trufflesuite.com/docs/truffle/reference/configuration#resolving-naming-conflicts-on-windows – Ashutosh Singh Oct 30 '20 at 10:52
  • @AshutoshSingh: This question was posted when truffle 4 was the latest version. – goodvibration Oct 30 '20 at 10:55
  • I understand, the reason I added this comment because I just copied an example built with older truffle version, and I saw truffle.js file. So anyone in future having this situation might have this question.... Hence just put it here for reference – Ashutosh Singh Oct 30 '20 at 11:02

5 Answers5

24

On windows systems having truffle.js in your main folder may create a conflict when you try to execute truffle.

Windows first try for executables in your current directory, and .js files are considered executables, then when it tries to execute your configuration file it will fail.

To be compatible with windows you can either rename your configuration file to truffle-config.js or execute truffle with truffle.cmd.

If you do not care about windows then you can use truffe.js.

Ismael
  • 30,570
  • 21
  • 53
  • 96
8

Just for reference, as of Truffle v5, truffle-config.js is now the default (and only file that is created) when initializing a new project. Documentation is available here.

Filip Š
  • 105
  • 4
Kevin Bluer
  • 81
  • 1
  • 3
4

truffle.js

and do add the following to it

module.exports = {
  networks: {
    development: {
      host: "localhost",
      port: 8545,
      network_id: "*" // Match any network id
    }
  }
};
Praveen Kumar
  • 139
  • 2
  • 9
4

You should use truffle.js


And from this page of Truffle docs my understanding is that:

  • Both files are created on initiation because default configuration file name can cause a conflict with the truffle executable, and so you may not be able to run Truffle commands properly on existing projects.
Roman Frolov
  • 3,177
  • 2
  • 11
  • 29
2

Truffle does not distinguish between truffle.js and truffle-config.js.

So, an easy way to deal with this, as referenced in Mastering Ethereum, is to simply delete this and use truffle-config.js instead.

Vignesh Karthikeyan
  • 1,950
  • 1
  • 12
  • 40
  • truffle-config.js works for me. Since the infromation dropped down an useful answer for it "- is properly configured in your Truffle configuration file (truffle-config.js)". I'm using Linux – Ender Feb 20 '19 at 03:48