Ionic cannot add android platform

I am trying to add the android platform using the following command

ionic platform add android

I am presented with the following output:

Creating android project...

module.js:340
    throw err;
          ^
    Error: Cannot find module 'which'
        at Function.Module._resolveFilename (module.js:338:15)
        at Function.Module._load (module.js:280:25)
        at Module.require (module.js:364:17)
        at require (module.js:380:17)
        at Object.<anonymous> (/Users/user1/.cordova/lib/npm_cache/cordova-android/3.6.4/package/bin/lib/check_reqs.js:27:13)
        at Module._compile (module.js:456:26)
        at Object.Module._extensions..js (module.js:474:10)
        at Module.load (module.js:356:32)
        at Function.Module._load (module.js:312:12)
        at Module.require (module.js:364:17)
    Error: /Users/user1/.cordova/lib/npm_cache/cordova-android/3.6.4/package/bin/create: Command failed with exit code 8
        at ChildProcess.whenDone (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:135:23)
        at ChildProcess.emit (events.js:98:17)
        at maybeClose (child_process.js:756:16)
        at Process.ChildProcess._handle.onexit (child_process.js:823:5)

I have set the PATH in my bash_rc file as such:

export PATH=/Users/user1/android-sdk-macosx/platform-tools:/Users/user1/android-sdk-macosx/tools:$PATH

Adding the iOS platform was simple; no problems there.

I checked my Android SDK and everything seems to be up to date. I also tried reinstalling cordova with sudo npm -g uinstall cordova followed by sudo npm -g install cordova

I have checked that npm, cordova, and ionic have been installed globally.

Check in the directory

/Users/user1/.cordova/lib/npm_cache/cordova-android/3.6.4/package/bin/node_modules/

There should be three modules in this directory, which, shelljs and q. They are part of the cordova-android 3.6.4 release so it is hard to see why one would be missing. If which is not there it might be best to remove the android platform and add it again.

ionic platform rm android

Update after your comment.

I don't think reinstalling the android platform will make any difference. It looks more like a node issue specific to your environment. The check_reqs script that is failing is run from the

/Users/user1/.cordova/lib/npm_cache/cordova-android/3.6.4/package/bin/lib

directory. If you change to this directory then run node interactively you can run then run the command:

require('which')

If this fails run:

module.paths

which will print out the paths that node used to attempt to find the which module. There should be an entry for

/Users/user1/.cordova/lib/npm_cache/cordova-android/3.6.4/package/bin/node_modules

which is where the which module is.

Faced the same problem, found that there wasn't "which" folder and its contents in android\cordova\node_modules. Once I copied the which folder from .cordova\lib\npm_cache\cordova-android\3.6.4\package\bin\node_modules\which The build was successful