When the npm version that is bundled with Cordova (2.15.12) is in PATH, adding Cordova platforms fails. The cause is that some npm packages are missing after cordova-android is installed.
I tried to reproduce this, but I accidentally triggered a slightly different error message than intended.
$ cordova create example
Creating a new cordova project.
$ cd example/
$ npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.
See `npm help json` for definitive documentation on these fields
and exactly what they do.
Use `npm install <pkg> --save` afterwards to install a package and
save it as a dependency in the package.json file.
Press ^C at any time to quit.
About to write to /tmp/example/package.json:
"description": "A sample Apache Cordova application that responds to the deviceready event.",
"test": "echo \"Error: no test specified\" && exit 1"
"author": "Apache Cordova Team",
Is this ok? (yes)
$ npm install cordova
... [TRUNCATED] ...
$ PATH="$(npm bin):$PATH" cordova platform add android
Using cordova-fetch for cordova-android@~6.2.2
Adding xmldom project...
Error: Your xmldom platform does not have Api.js
In the above example, cordova is installed in the same directory as where cordova-fetch stores them. The error I originally encountered, can be triggered using the following commands:
$ rm -r platforms/ plugins/ node_modules/
$ PATH="$(npm -g prefix)/lib/node_modules/cordova/bin:$PATH" cordova platform add android
Using cordova-fetch for cordova-android@^6.2.3
Error: Platform android already added.
The example shows the error for the android platform, but the same error occurs when using cordova-ios.