apache / cordova

Apache Cordova
https://cordova.apache.org/
584 stars 61 forks source link

Error in esbuild js bundle when loaded into the UI #327

Closed Ajju2211 closed 2 years ago

Ajju2211 commented 2 years ago

Bug Report

The error was due to this line in javascript user?.name?.verified

Problem

I am getting error in the js bundle when loaded into the UI which is built from esbuild for my create-react-app. Previously I was using default create-react-app webpack build but for faster build time I am using esbuild. The error was due to this line in js. user?.name?.verified I think this was due to ES5 or ES6 support issue. Please le me know. And also which browser version is used in cordova.

What is expected to happen?

It should not given any error for this line.In react-scripts build it was working.But only does not working in the esbuild bundle.

What does actually happen?

Information

Command or Code

cordova run

Environment, Platform, Device

Android 10

Version information

Cordova 11.0.0 version.

Checklist

breautek commented 2 years ago

And also which browser version is used in cordova.

Cordova uses the system webview. Cordova itself is not a browser engine and does not provide support for any ES features. Support for ES features relies purely on the underlying system browser engine. You can think of Cordova more like a packaging tool which packages your web assets into the native bundle.

For Android, the webview is decoupled from the OS and the user can upgrade the webview through Google Play. The webview is usually based off of Chrome. This means a single device could have a wide range of versions installed. For example, Android 7 factory comes with Chrome 53, but can be updated to the current latest through Google Play. You can observe this if you install a Google Play enabled emulator in Android Studio.

The error was due to this line in js. user?.name?.verified I think this was due to ES5 or ES6 support issue.

Caniuse is an excellent resource to check for compatibility, but for the case of optional chaining syntax, you can see that support was added in Chrome fairly recently on Chrome 80 in the desktop version, but the Android Browser (aka the android webview), support for it prior to version 100 is actually unknown.

So to reliably use optional chaining, you must provide a polyfill or a build-time transpile using tools such as babel. I think react projects automatically include babel if I recall correctly.

For this reason I'm closing this as not a bug.