3

When I am trying to create new truffle project with truffle init in a not empty folder (with IDE folder and .gitignore file) I have received an error:

Error: Something already exists at the destination. Please unbox in an empty folder. Stopping to prevent overwriting data. at C:\Users\...\Roaming\npm\node_modules\truffle\build\webpack:\~\truffle-box\lib\utils\unbox.js:22:1 at <anonymous> at process._tickCallback (internal/process/next_tick.js:188:7) at Function.Module.runMain (module.js:686:11) at startup (bootstrap_node.js:187:16) at bootstrap_node.js:608:3

How can I force truffle to create a new project in any case?

  • Follow the hint given to you by Truffle - Please unbox in an empty folder (a few exclamation marks would probably be in place at this point). First call truffle init in an empty folder, and then copy the output to anywhere you want. – goodvibration May 21 '18 at 9:42
  • @goodvibration I hope some additional flag exists, something like --force, if I am shure that I want to init project in this not empy directory in any case – Dmytro Zarezenko May 21 '18 at 9:52
  • No such flag. I can show you where to disable that in Truffle source code if you want (which you will have to do after every time you call npm install), and hell, you could even add your own flag in there two... But I think that the steps I suggested in my previous comment are a better way of achieving this goal. – goodvibration May 21 '18 at 9:58
  • I answered this question here. Please validate it ethereum.stackexchange.com/a/54951/43838 – shantanu chandra Jul 23 '18 at 13:34
1

Follow the hint given to you by Truffle - Please unbox in an empty folder (a few exclamation marks would have probably been appropriate at this point):

First call truffle init in an empty folder, and then copy the output to anywhere you want.

Alternatively, you can at your own risk change Truffle source code after you call npm install:

  1. Open file ./node_modules/truffle/build/cli.bundled.js in a text editor
  2. Search for Please unbox in an empty folder, and you will find this function:

function checkDestination(destination) {
  return Promise.resolve().then(function() {

    var contents = fs.readdirSync(destination);
    if (contents.length) {
      var err = "Something already exists at the destination. " +
                "Please unbox in an empty folder. " +
                "Stopping to prevent overwriting data."

      throw new Error(err);
    }
  })
}

  1. Replace throw new Error(err); with console.warn(err);

You could also write a JS script to do that, and embed it into your package.json file as follows:

"scripts": {
    "install": "node my-script.js"
}

So that you don't have to do the whole thing manually after every npm install.

It's a "legitimate" way to fix a bug in Truffle (or any other npm package for that matter), until it is resolved by the author itself.

The only thing is, the problem that you've encountered is far from being a bug.

0

You can use truffle init --force.

According to this truffle docs page:

You can use an optional --force to initialize the project in the current directory regardless of its state (e.g. even if it contains other files or directories). This applies to both the init and unbox commands. Be careful, this will potentially overwrite files that exist in the directory.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.