title: Cordova Build fails on OS X with EACCES & ENOENT
body: <p>I recently started building iOS apps using Cordova and I’ve hit a roadblock. After installing nodeJS, git and cordova (with sudo), I created my first app in the Documents folder of my user account. </p>
  
  <p>The first run went perfectly. Everything worked, and adding my dev account to Xcode helped my app to run on the device. I decided I’d spice things up a bit by adding a “before_prepare” hook called <code>001_c.js</code> in <code>&lt;appName&gt;/hooks/before_prepare folder</code>. This is how the hook begins:</p>
  
  <pre><code>//This is where nodeJS exists
  #!/usr/local/bin node
  
  console.log("Changing config");
  
  var fs = require('fs');
  var path = require('path');
  
  var rootdir = process.argv[2];
  
  //and so on
  </code></pre>
  
  <p>When I now build the app, I get this error:</p>
  
  <blockquote>
    <p>pc295786:master kellster$ cordova build ios Running command:
    /Users/kellster/documents/apps/master/hooks/before_prepare/001_c.js
    /Users/kellster/documents/apps/master Error: spawn <strong><em>EACCES</em></strong>
        at exports._errnoException (util.js:746:11)
        at ChildProcess.spawn (child_process.js:1155:11)
        at Object.exports.spawn (child_process.js:988:9)
        at Object.exports.spawn (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:104:31)
        at runScriptViaChildProcessSpawn (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/hooks/HooksRunner.js:188:23)
        at runScript (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/hooks/HooksRunner.js:131:16)
        at /usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/hooks/HooksRunner.js:114:20
        at _fulfilled (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:787:54)
        at self.promiseDispatch.done (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:816:30)
        at Promise.promise.promiseDispatch (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:749:13)</p>
  </blockquote>
  
  <p>To troubleshoot, I changed the first line of the hook script from </p>
  
  <pre><code>#!/usr/local/bin node
  </code></pre>
  
  <p>to </p>
  
  <pre><code>#! node
  </code></pre>
  
  <p>(Because this worked on Windows. <code>node</code> was in global scope). But, this resulted in an ENOENT error:</p>
  
  <blockquote>
    <p>pc295786:master kellster $ cordova build ios Running command:
    /Users/kellster/documents/apps/master/hooks/before_prepare/001_c.js
    /Users/kellster/documents/apps/master Error: Hook failed with error
    code <strong><em>ENOENT</em></strong>:
    /Users/kellster/documents/apps/master/hooks/before_prepare/001_c.js
        at /usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/hooks/HooksRunner.js:194:23
        at _rejected (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:797:24)
        at /usr/local/lib/node_modules/cordova/node_modules/q/q.js:823:30
        at Promise.when (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:1035:31)
        at Promise.promise.promiseDispatch (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:741:41)
        at /usr/local/lib/node_modules/cordova/node_modules/q/q.js:557:44
        at flush (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:108:17)
        at process._tickCallback (node.js:355:11)
        at Function.Module.runMain (module.js:503:11)
        at startup (node.js:129:16)</p>
  </blockquote>
  
  <p><strong>How do I get this to build?</strong> I’d appreciate any suggestions I could try.</p>
  
  <hr>
  
  <p><em>Some things to note:</em></p>
  
  <ol>
  <li>(In my desperation, ) I tried running the following commands, because the "EACCES" type of error. But none of them seemed to have any kind of effect on the result. The build was still failing.  </li>
  </ol>
  
  <blockquote>
  <pre><code>sudo chmod 777 “/Users/kellster/documents/apps/master"
  sudo chmod 777 “/usr/local/lib”
  sudo chmod 777 "/usr/local/bin/"
  chmod 777 "/Users/kellster/documents/apps/master/platforms/"
  sudo chmod a+rwx "/Users/kellster/Documents/apps/Master/hooks/before_prepare/001_c.js"
  sudo chmod a+rwx "/Users/kellster/Documents/apps/Master/"
  sudo chown -R kellster /usr/local/lib/node_modules/cordova
  </code></pre>
  </blockquote>
  
  <p>2) Node is installed in </p>
  
  <blockquote>
    <p>/usr/local/bin</p>
  </blockquote>