Home » Android » cordova – Ionic – Unexpected token ILLEGAL only when running in Android 5 emulator

cordova – Ionic – Unexpected token ILLEGAL only when running in Android 5 emulator

Posted by: admin May 14, 2020 Leave a comment

Questions:

I’m developing an Ionic application and I’m facing the following problem:

Unexpected token ILLEGAL

The strange thing is that it only occurs when I run the application in Genymotion emulator with Android 5 and bellow, using ionic cordova run android. If I run the same code in Android 6 and above the application runs correctly.

The console is saying the problem is near the ‘{‘ character:

enter image description here

I tryied rewrite this piece of code, but it only change the error to another line, if I delete all white spaces.

The weird thing here is that it only occurs when running in the emulator, so I’m suspecting from something in project configuration, like webpack.

Ionic version: 3.19.0
cordova-android: ^6.2.3

This is my package.json

{
    "scripts": {
        "clean": "ionic-app-scripts clean",
        "build": "ionic-app-scripts build",
        "lint": "ionic-app-scripts lint",
        "ionic:build": "ionic-app-scripts build",
        "ionic:serve": "ionic-app-scripts serve"
    },
    "dependencies": {
        "@angular/common": "5.0.1",
        "@angular/compiler": "5.0.1",
        "@angular/compiler-cli": "5.0.1",
        "@angular/core": "5.0.1",
        "@angular/forms": "5.0.1",
        "@angular/http": "5.0.1",
        "@angular/platform-browser": "5.0.1",
        "@angular/platform-browser-dynamic": "5.0.1",
        "@ionic-native/camera": "^4.4.2",
        "@ionic-native/core": "4.3.2",
        "@ionic-native/date-picker": "^4.4.2",
        "@ionic-native/facebook": "^4.4.2",
        "@ionic-native/globalization": "^4.4.2",
        "@ionic-native/google-plus": "^4.4.2",
        "@ionic-native/onesignal": "^4.4.2",
        "@ionic-native/splash-screen": "4.3.2",
        "@ionic-native/status-bar": "4.3.2",
        "@ionic/storage": "^2.1.3",
        "@ngx-translate/core": "^9.0.1",
        "@ngx-translate/http-loader": "^2.0.0",
        "cordova-android": "^6.2.3",
        "cordova-plugin-camera": "^2.4.1",
        "cordova-plugin-compat": "^1.2.0",
        "cordova-plugin-datepicker": "^0.9.3",
        "cordova-plugin-device": "1.1.4",
        "cordova-plugin-facebook4": "^1.9.1",
        "cordova-plugin-globalization": "^1.0.8",
        "cordova-plugin-googleplus": "^5.1.1",
        "cordova-plugin-ionic-webview": "^1.1.11",
        "cordova-plugin-splashscreen": "~4.0.1",
        "cordova-plugin-whitelist": "1.3.1",
        "cordova-sqlite-storage": "^2.1.2",
        "font-awesome": "^4.7.0",
        "ionic-angular": "3.9.2",
        "ionic-plugin-keyboard": "~2.2.1",
        "ionicons": "3.0.0",
        "moment": "^2.19.2",
        "ngx-cookie-service": "^1.0.9",
        "onesignal-cordova-plugin": "^2.2.2",
        "rxjs": "5.5.2",
        "sw-toolbox": "3.6.0",
        "zone.js": "0.8.18"
    },
    "devDependencies": {
        "@ionic/app-scripts": "3.1.0",
        "typescript": "2.4.2"
    },
    "config": {
        "ionic_copy": "./config/copy.config.js"
    },
    "cordova": {
        "plugins": {
            "cordova-plugin-device": {},
            "cordova-plugin-ionic-webview": {},
            "cordova-plugin-splashscreen": {},
            "cordova-plugin-whitelist": {},
            "ionic-plugin-keyboard": {},
            "cordova-plugin-facebook4": {
                "APP_ID": "",
                "APP_NAME": ""
            },
            "cordova-plugin-datepicker": {},
            "cordova-plugin-googleplus": {
                "REVERSED_CLIENT_ID": ""
            },
            "cordova-plugin-globalization": {},
            "cordova-plugin-camera": {},
            "onesignal-cordova-plugin": {},
            "cordova-sqlite-storage": {}
        },
        "platforms": [
            "android"
        ]
    }
}

Ionic info:

cli packages: (/opt/nvm/versions/node/v7.10.0/lib/node_modules)

@ionic/cli-utils  : 1.19.0
ionic (Ionic CLI) : 3.19.0

global packages:

    cordova (Cordova CLI) : 7.0.1 

local packages:

    @ionic/app-scripts : 3.1.0
    Cordova Platforms  : android 6.2.3
    Ionic Framework    : ionic-angular 3.9.2

System:

    Android SDK Tools : 26.1.1
    Node              : v7.10.0
    npm               : 4.2.0 
    OS                : Linux 4.4

Environment Variables:

    ANDROID_HOME : /opt/android-sdk-linux

Misc:

    backend : pro
How to&Answers:

It appears there’s an adjustment to make in

node_modules/@ionic/app-scripts/dist/template.js

change to this:

return getTemplatePrefix(htmlFilePath) + “‘” + content + “‘” +
getTemplateSuffix(htmlFilePath);

some backticks to remove. I read here: [Module parse failed: Unexpected token ionic 3