Skip to content
This repository has been archived by the owner on Apr 11, 2022. It is now read-only.

Phonegap is unable to install cordova plugins: The platform "browser" does not appear to be a valid cordova platform #749

Closed
ferreiro opened this issue Oct 28, 2017 · 12 comments
Labels
Milestone

Comments

@ferreiro
Copy link

ferreiro commented Oct 28, 2017

PhoneGap CLI, node & npm versions

Node: v8.5.0
Phonegap: v7.1.1
npm: v5.3.0
macOS: Sierra 10.12.6

Expected Behaviour

When running the command $ phonegap plugin add plugin-name it installs correctly the plugin (including all the platform dependencies and needed assets).

Actual Behaviour

Phonegap CLI fails to install new plugins, because the browser platform is missing API.js.

Steps to Reproduce

  1. Install phonegap (v7.1.1).
  2. Execute in the command line this script: $ phonegap plugin add cordova.plugins.diagnostic

Error messages

$ phonegap plugin add cordova.plugins.diagnostic
Installing "cordova.plugins.diagnostic" for browser  
  
Unable to load PlatformApi from platform. Error: Cannot find module '/Users/george/Documents/phonegap/TryPushNotifications/platforms/browser/cordova/Api.js'  
  
Failed to install 'cordova.plugins.diagnostic': Error: Unhandled "error" event. (The platform "browser" does not appear to be a valid cordova platform. It is missing API.js. browser not supported.)  
    at EventEmitter.emit (events.js:185:19)  
    at EventEmitter.module.exports.emit (/usr/local/lib/node_modules/phonegap/node_modules/cordova-common/src/events.js:71:17)  
    at Object.getPlatformApiFunction (/usr/local/lib/node_modules/phonegap/node_modules/cordova-lib/src/cordova/util.js:500:20)  
    at Object.getPlatformApi (/usr/local/lib/node_modules/phonegap/node_modules/cordova-lib/src/platforms/platforms.js:55:25)  
    at handleInstall (/usr/local/lib/node_modules/phonegap/node_modules/cordova-lib/src/plugman/install.js:593:29)  
    at /usr/local/lib/node_modules/phonegap/node_modules/cordova-lib/src/plugman/install.js:357:28  
    at _fulfilled (/usr/local/lib/node_modules/phonegap/node_modules/q/q.js:787:54)  
    at self.promiseDispatch.done (/usr/local/lib/node_modules/phonegap/node_modules/q/q.js:816:30)  
    at Promise.promise.promiseDispatch (/usr/local/lib/node_modules/phonegap/node_modules/q/q.js:749:13)  
    at /usr/local/lib/node_modules/phonegap/node_modules/q/q.js:509:49  
  
Error: Unhandled "error" event. (The platform "browser" does not appear to be a valid cordova platform. It is missing API.js. browser not supported.)  
@ferreiro ferreiro changed the title Unable to install cordova plugins: The platform "browser" does not appear to be a valid cordova platform Unable to install cordova plugins on Phonegap: The platform "browser" does not appear to be a valid cordova platform Oct 28, 2017
@ferreiro ferreiro changed the title Unable to install cordova plugins on Phonegap: The platform "browser" does not appear to be a valid cordova platform Phonegap is unable to install cordova plugins: The platform "browser" does not appear to be a valid cordova platform Oct 28, 2017
@surajpindoria
Copy link
Collaborator

I think this may just be an issue with an outdated version of cordova-browser. Just tried this on my machine and didn't see any problems. Could you try removing the browser platform and using the latest version, phonegap platform add browser && phonegap platform add browser.

@surajpindoria surajpindoria added this to the User Support milestone Oct 30, 2017
@ferreiro
Copy link
Author

ferreiro commented Nov 1, 2017

Hi @surajpindoria! Thanks so much for getting back to me.

Yes, it worked to remove browser platform and add it again. I think there is a problem with phonegap templates generator, which installs old or corrupted browser version. Problem solved! Thanks!

@ferreiro ferreiro closed this as completed Nov 1, 2017
@surajpindoria
Copy link
Collaborator

Great that you got it solved!

And I think what happened is you may have ran phonegap serve which auto-adds the latest browser platform. But then as we updated the CLI tooling it required a newer version of the platform which is why you were seeing those errors.

@ferreiro
Copy link
Author

ferreiro commented Nov 7, 2017

@surajpindoria hmmm. Actually I don't use phonegap serve command. Instead, I used Phonegap 2 mac application (for creating the project and also launching the server). So what's happening in this case?

@surajpindoria
Copy link
Collaborator

The PhoneGap Desktop app is still using phonegap serve behind the scenes. So it is adding the browser platform as well.

@ferreiro
Copy link
Author

ferreiro commented Nov 9, 2017

Ahh! Okey! Thankx

@zerox1212
Copy link

zerox1212 commented Dec 27, 2017

Just wanted to say that this still happens if you run a project from Phonegap Desktop, then afterwards try to install a plugin.

The advice above also has a typo, people who have this issue must run this from the CLI:
phonegap platform rm browser && phonegap platform add browser
(above text has "add" twice instead of "rm")

@emipmttt
Copy link

emipmttt commented Mar 4, 2018

how solve this so? i want install admob plugin but cannot find: platforms\browser\cordova\api.js

I try with
phonegap platform rm browser && phonegap platform add browser
but dont works

@keithkrugh
Copy link

Try separating the commands.
For example, do this one first: phonegap platform rm browser
After the above executes do this one: phonegap platform add browser

@felipedrumond
Copy link

It did work, but when I run the app, I get this errors

cordova.js:1534 GET http://10.0.0.1:3000/cordova_plugins.js 500 (Internal Server Error) exports.injectScript @ cordova.js:1534 injectIfNecessary @ cordova.js:1542 exports.load @ cordova.js:1622 (anonymous) @ cordova.js:1142 setTimeout (async) (anonymous) @ cordova.js:1141 build @ cordova.js:51 require @ cordova.js:66 (anonymous) @ cordova.js:1861 (anonymous) @ cordova.js:1863 (index):1 Refused to execute script from 'http://10.0.0.1:3000/cordova_plugins.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.

@golyalpha
Copy link

Your CSP is preventing you from running something with MIME type of 'text/html', but why is that script being served as that mime type instead of text/javascript is another issue.

@PaulCombal
Copy link

Finally found it, I had a very similar issue with android. Before this message I had to install several npm modules:

npm i q properties-parser cordova-common shelljs

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

8 participants