8

I have an issue when trying to update any plugin in cordova using mac os terminal. When I try to run the command cordova plugin add xxxxxxx it is telling me that both my android/ios are not valid cordova platforms.

My Node version is v9.2.0, NPM version is 5.5.1 and Cordova version is 7.1.0. I'm at a loss on how to proceed. Can anyone give some insight?

 ➜  steve git:(master) ✗ cordova plugin add https://github.com/danwilson/google-analytics-plugin.git
 Installing "cordova-plugin-google-analytics" for ios
 Unable to load PlatformApi from platform. Error: Cannot find module '/Users/rsteve/Desktop/steve/platforms/ios/cordova/Api.js'
Failed to install 'cordova-plugin-google-analytics': 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.)
at EventEmitter.emit (events.js:140:19)
at EventEmitter.module.exports.emit (/usr/local/lib/node_modules/cordova/node_modules/cordova-common/src/events.js:71:17)
at Object.getPlatformApiFunction (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/util.js:500:20)
at Object.getPlatformApi (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/platforms/platforms.js:55:25)
at handleInstall (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/plugman/install.js:593:29)
at /usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/plugman/install.js:357:28
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)
at /usr/local/lib/node_modules/cordova/node_modules/q/q.js:509:49

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

enter image description here

chronotrigga
  • 589
  • 1
  • 10
  • 33
  • 5
    Sounds like an incompatibility between node and Cordova, can you try with node 6? also, what cordova-ios and cordova-android platforms are you using? – jcesarmobile Nov 29 '17 at 11:58
  • it's weird because normally i don't get the git:(master). it's normally just the folder path. how can i find out the version of cordova-ios + cordova-android? – chronotrigga Nov 29 '17 at 14:51
  • with `cordova platforms` command – jcesarmobile Nov 29 '17 at 16:12
  • ios 4.5.4. android platform isn't installed. – chronotrigga Nov 29 '17 at 16:27
  • If the platform was added with node 9 installed then it's a compatibility problem. If it was created with an older version of node try removing and adding the ios platform again. Workarounds might be to downgrade node to 6 or cordova to 6.0.0 – jcesarmobile Nov 29 '17 at 16:58
  • It was created with an older version of node. I was able to remove ios and add it back fine. But the cordovalib was missing. When I added it back in xcode, it told me that AppDelegate.h was missing even though the file is there. – chronotrigga Nov 29 '17 at 17:17
  • I downgraded my node to 6.0 but still suffering the same issue. When trying to remove the necessary plugin using `cordova plugins rm` command it assumes i'm trying to remove it from the android platform which doesn't actually exist. – chronotrigga Nov 29 '17 at 17:37
  • @jcesarmobile https://i.imgur.com/3SU6kN1.png -- when i rebuild ios I always get this lexical or preprocessor issue trying to run in xcode. i did the `header search path fix` but still running into the error. any advice? – chronotrigga Nov 29 '17 at 19:10
  • CDVJSON.h was removed in cordova-ios 4, you should check if that plugin has an update to support it or use another plugin – jcesarmobile Nov 29 '17 at 19:24
  • @jcesarmobile i see it references SQLitePlugin.h which is one of our plugins but the issue is i can't add or remove any plugins due to the original error above. any other suggestions you think i should try? – chronotrigga Nov 29 '17 at 19:54

2 Answers2

3

In my experience, the following resolves almost all cordova plugin/platform issues:

cordova plugins --save
cordova platforms --save
rm -rf platforms
rm -rf plugins
cordova prepare

It does this by:

  1. saving plugin config
  2. saving platform config
  3. removing platforms folder
  4. removing plugins folder
  5. re-installing all platforms and plugins
John Doherty
  • 3,669
  • 36
  • 38
0

It seems like your node version is not supported with cordova / ionic

Solution:

  • Downgrade node: Downgrade your node version (use recommended version form node js) or try with node 6.x.x

  • Install Git: Have you installed Git on your machine? Cordova requires git to clone plugins from server

  • Permissions: Make sure your folder has read/write permission; or try with admin rights

  • Install directly from Git: you can install plugins directly from git by using git clone plugin-url and then install cordova plugin add -d /plugin-path/
Sundaravel M
  • 236
  • 2
  • 9
  • unfortunately i have used node v6.6.0 and still does not work. i believe git is installed yes, but does it require updating? and i have tried sudo with admin rights and still the same issue. – chronotrigga Dec 12 '17 at 20:36
  • Try remove platform `cordova platform rm ios` and then add it again by using `cordova platform add ios@latest` – Sundaravel M Dec 13 '17 at 03:59