[ionic v4] build for browser. Could not find cordova.js script tag.
See original GitHub issueBug Report
Ionic version: [x] 4.12.0
Current behavior: My project offers Android, web services as ionic. I used v3 and I recently migrated to v4.
Android is no problem. The web service uses firebase hosting, and the following error is displayed on the console. Could not find cordova.js script tag. Plugin loading may fail. This.platform.is(‘cordova’) also returns true.
This does not occur in the development environment (local deployment).
Expected behavior: On the web, this.platform.is(‘cordova’) should be false. And cordova_plugins.js should not be added automatically.
Steps to reproduce: We have built the following for web deployment: ionic cordova build browser --prod
Other information: After the build, the script is added automatically as shown below. platforms/browser/www/index.html
<script type="text/javascript" src="runtime.2e60a16c6e117d385511.js"></script><script type="text/javascript" src="es2015-polyfills.b6a15bd967a1a7dbe1a0.js" nomodule></script><script type="text/javascript" src="polyfills.3b992854afcaadf84bec.js"></script><script type="text/javascript" src="cordova.be00a3c9f5babbb22844.js"></script><script type="text/javascript" src="main.d1dd04adbe6dd750e532.js"></script>
After the deploy, cordova_plugins.js was added automatically in the head tag.
<script src="cordova_plugins.js"></script>
Ionic info:
Ionic:
ionic (Ionic CLI) : 4.12.0 (/usr/local/lib/node_modules/ionic)
Ionic Framework : @ionic/angular 4.1.1
@angular-devkit/build-angular : 0.13.5
@angular-devkit/schematics : 7.2.4
@angular/cli : 7.3.5
@ionic/angular-toolkit : 1.4.0
Cordova:
cordova (Cordova CLI) : 8.1.2 (cordova-lib@8.1.1)
Cordova Platforms : android 8.0.0, browser 5.0.4
Cordova Plugins : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 3.1.2, (and 17 other plugins)
System:
Android SDK Tools : 26.1.1 (/Users/hscho/Library/Android/sdk)
ios-deploy : 1.9.2
ios-sim : 6.1.2
NodeJS : v10.12.0 (/usr/local/bin/node)
npm : 6.9.0
OS : macOS Mojave
Xcode : Xcode 10.2.1 Build version 10E1001
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:10 (5 by maintainers)
I misunderstood your answer. I understood you to say the following: Do not use cordova to develop web application. for web application, redevelop without cordova. Sorry.
The issue is resolved using:
thank you.
@gudtkd928 - I just noticed you are using Cordova’s
browser
platform. That is not really a good practice for deploying a web application. Instead, you should develop your application to use Cordova plugins in a cordova context (this.platform.is('cordova')
) and a web API in a non-cordova context.The browser platform is more or less a “testing” platform and not really something that is good for deployment. Many plugins do not work with the browser platform, and others provide fake testing data when used with the browser platform. Web APIs, or using Capacitor instead of Cordova, are far better options if you want to do a web deployment and target browsers as well as doing a hybrid native implementation.
If you want to target the browser without a hybrid native target (which I have done with a couple of apps), then I would remove the Cordova layer entirely and just use web APIs.