phonegap / phonegap-cli

PhoneGap and PhoneGap/Build command-line interface
Apache License 2.0
489 stars 157 forks source link

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

Closed ferreiro closed 6 years ago

ferreiro commented 6 years ago

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.)  
surajpindoria commented 6 years ago

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.

ferreiro commented 6 years ago

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!

surajpindoria commented 6 years ago

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 commented 6 years ago

@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 commented 6 years ago

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

ferreiro commented 6 years ago

Ahh! Okey! Thankx

zerox1212 commented 6 years ago

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 commented 6 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 3 years ago

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