Javascript error "Unexpected strict mode reserved word" while using d3.js with apache codrova

Viewed 321

I would like to use d3.js for showing graphs in my apache cordova app. To avoid unnecessary traffic there is a local d3.min.js file loaded via

<script src="js/d3.min.js"></script>

However I got the javascript error while starting the app in the android emulator

Android API-Level 22 (Android 5.1)

Uncaught SyntaxError: Unexpected strict mode reserved word  @d3.min.js:2

Android API-Level 23 (Android 6)

Uncaught SyntaxError: Unexpected token => @ d3.js:19

There is no "use strict" in my code. To verify the issue I created a bare cordova project, included d3.js with the code above and got the same error.

Any idears on how to load d3.js without using strict mode in cordova?

I am using

d3.js 6.3.0
Android Studio 4.1.1        
Cordova 10.0.0

with

"cordova-android": "^9.0.0",
"cordova-plugin-file": "^6.0.2",
"cordova-plugin-splashscreen": "^6.0.0",
"cordova-plugin-whitelist": "^1.3.4"
1 Answers

This happens if the installed android webview is an out-dated version of Chrome. While Android has an independently update-able webview starting in Android 5.0... it doesn't mean all users actually do install updates, and sometimes some vendors cut off updates after sometime.

If you're using Google API enabled emulators, you can login to the Google Play store and should receive updates, including android webview updates.

But you may also want to run d3.js through a transpiler such as Babel to transpile modern JS features into more compatible version such as ES3 javasacript. This will convert usages of let to var for example, or () => {} arrow functions into traditional function () {} functions. This will make d3.js compatible with older webview versions that may be running on some of your clients.

Related