Unable to build or add iOS - unable to load platform api - please help

When I run ionic cordova build ios the output is as follows

> cordova platform add ios --save
Using cordova-fetch for cordova-ios@3.9.0

Adding ios project...

iOS project created with cordova-ios@3.9.0
Unable to load PlatformApi from platform. Error: Unhandled "error" event. (Does not appear to implement platform Api.)

(node:22344) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Unhandled "error" event. (The platform "ios" does not appear to be a valid cordova platform. It is missing API.js. ios not supported.)
(node:22344) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

[WARN] Detected @ionic/cli-plugin-cordova in your package.json.

       As of CLI 3.8, it is no longer needed. You can uninstall it:

       npm uninstall -D @ionic/cli-plugin-cordova


[WARN] Detected @ionic/cli-plugin-ionic-angular in your package.json.

       As of CLI 3.8, it is no longer needed. You can uninstall it:

       npm uninstall -D @ionic/cli-plugin-ionic-angular


Running app-scripts build: --platform ios --target cordova
[18:39:11]  build dev started ...
[18:39:11]  clean started ...
[18:39:11]  clean finished in 2 ms
[18:39:11]  copy started ...
[18:39:11]  transpile started ...
[18:39:14]  transpile finished in 2.15 s
[18:39:14]  preprocess started ...
[18:39:14]  deeplinks started ...
[18:39:14]  deeplinks finished in 28 ms
[18:39:14]  preprocess finished in 29 ms
[18:39:14]  webpack started ...
[18:39:14]  copy finished in 2.31 s
[18:39:20]  webpack finished in 5.92 s
[18:39:20]  sass started ...
[18:39:20]  sass finished in 762 ms
[18:39:20]  postprocess started ...
[18:39:20]  removed unused font files
[18:39:20]  postprocess finished in 5 ms
[18:39:20]  lint started ...
[18:39:20]  build dev finished in 8.94 s
> cordova build ios
(node:22358) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): CordovaError: No platforms added to this project. Please use `cordova platform add <platform>`.
(node:22358) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

[18:39:22]  lint finished in 1.55 s

From reading the error message it says Please use cordova platform add <platform>

So I run cordova platform add ios

I get

Adding ios project...
Unable to load PlatformApi from platform. Error: Unhandled "error" event. (Does not appear to implement platform Api.)
Error: Project already exists

I have no idea what to do? Ive been hitting my head against the wall for a couple hours on this.

1 Like

Hi ,

Remove the platform which you try to run on it (browser, ios, android, and etc.)
cordova platform rm browser

Add the platform again
cordova platform add browser

You can run
cordova run browser

2 Likes

I got myself in quite the pickle. To get out of it I took some drastic measures.

I updated the iOS platform from 3.9.0 to 4.5.4
I updated Cordova to 8.0 and Ionic to the latest
I then updated my operating system from El Capitain to Sierra
I updated X code to 9.2

I then did

  • rm -rf node_modules/ platforms/ios/
  • npm i
  • ionic cordova build ios
  • ** BUILD SUCCEEDED **

Not sure how I created such a mess but glad its figured out

1 Like

For one app these steps worked for another it did not :expressionless: