AjLearning
AjLearning

Reputation: 397

Can't build Cordova iOS project using CLI but can build/run the Xcode project

Absolutely new to Cordova. These are the steps I've done:

  1. Checked out an existing project
  2. run cordova build ios

The above generates this build error:

(node:10242) UnhandledPromiseRejectionWarning: Error [ERR_UNHANDLED_ERROR]: Unhandled error. (The platform "ios" does not appear to be a valid cordova platform. It is missing API.js. ios not supported.)

I've Googled for a solution to the above and the general consensus seems to be to remove and then add the iOS platform.

Now there's a problem with that. Looking through the commit history, I can see that there have been code changes done to files within the platforms directory so I can't just remove it, or...

Question 1) Can I?

Question 2) Is it right to make code changes within the platforms directory? Because it seems like those are generated directories.

Question 3) Why is it that when I open the Xcode project under platforms/ios, I am able to build/run it fine despite the Cordova CLI error above?

Upvotes: 1

Views: 976

Answers (1)

jcesarmobile
jcesarmobile

Reputation: 53301

it's not right to manually edit the platform files. And some manual changes might make the project not build, so might be related to the manual changes somebody did. So if you don't want to risk to remove the platform, continue building from Xcode

from root www to platforms/ios is transferred by cordova commands such us cordova prepare ios or cordova build ios or cordova run ios.

So if you can't do a cordova prepare ios because of that error you can try a few things.

  1. Copy your files from www to platforms/ios without replacing the whole folder, just the duplicate files. cordova prepare ios is not just a copy, it's also does some modifications/aditions, but if you don't remove existing files it might work.

  2. Create a new project and copy the platforms/ios/cordova to your own project and see if that fixes the mentioned problem, as that's where the Api.js file is.

  3. Downgrade the Cordova CLI, try to latest 7.x.x and if it doesn't work, try with latest 6.x.x, one of those won't require the Api.js as it relatively new.

Upvotes: 1

Related Questions