androidionic-frameworkionic6

Unexpected token ? during run ionic 6 application on android virtual device


I get this error:

JavaScript Error: {"type":"js.error","error":{"message":"Uncaught SyntaxError: Unexpected token ?","url":"http://localhost/vendor.js","line":24288,"col":28,"errorObject":"{}"}} File: http://localhost/ - Line 582 - Msg: SyntaxError: Unexpected token ? File: http://localhost/vendor.js - Line 24288 - Msg: Uncaught SyntaxError: Unexpected token ?

when I run the application in the android emulator. And the app does not want to start, just crashes and shows this error in Logcat. I was open that file and this is what I find in that line:

this._baseHref = href ?? this._platformLocation.getBaseHrefFromDOM() ?? (0,_angular_core__WEBPACK_IMPORTED_MODULE_0__.inject)(DOCUMENT).location?.origin ?? ''; which belongs to this: class PathLocationStrategy extends LocationStrategy

If helps I can share vendor.js file with you. But please help me or help me to address who is responsible for it.

Here is my package.json: "dependencies": { "@angular/common": "^14.2.3", "@angular/core": "^14.2.3", "@angular/forms": "^14.2.3", "@angular/platform-browser": "^14.2.3", "@angular/platform-browser-dynamic": "^14.2.3", "@angular/router": "^14.2.3", "@capacitor/android": "^4.3.0", "@capacitor/app": "^4.0.1", "@capacitor/core": "^4.3.0", "@capacitor/filesystem": "^4.1.1", "@capacitor/haptics": "^4.0.0", "@capacitor/ios": "^4.3.0", "@capacitor/keyboard": "^4.0.0", "@capacitor/status-bar": "^4.0.0", "@ionic-native/camera": "^5.36.0", "@ionic-native/core": "^5.36.0", "@ionic-native/file": "^5.36.0", "@ionic-native/splash-screen": "^5.36.0", "@ionic-native/status-bar": "^5.36.0", "@ionic/angular": "^6.2.9", "@ngx-translate/core": "^14.0.0", "@ngx-translate/http-loader": "^7.0.0", "animate.css": "^4.1.1", "cordova-plugin-camera": "^6.0.0", "cordova-plugin-file": "^7.0.0", "date-fns": "^2.29.0", "ionic-selectable": "^4.9.0", "rxjs": "~7.5.7", "tslib": "^2.4.0", "twilio-video": "^2.24.1", "zone.js": "~0.11.8" }, "devDependencies": { "@angular-devkit/architect": "^0.1402.4", "@angular-devkit/build-angular": "^14.2.3", "@angular-devkit/core": "^14.2.4", "@angular-eslint/builder": "~13.3.0", "@angular-eslint/eslint-plugin": "~13.3.0", "@angular-eslint/eslint-plugin-template": "~13.3.0", "@angular-eslint/template-parser": "~13.3.0", "@angular/cli": "^14.2.3", "@angular/compiler": "^14.2.3", "@angular/compiler-cli": "^14.2.3", "@angular/language-service": "^14.2.3", "@capacitor/cli": "^4.0.0", "@ionic/angular-toolkit": "^7.0.0", "@types/jasmine": "~3.6.0", "@types/jasminewd2": "~2.0.3", "@types/node": "^12.11.1", "@typescript-eslint/eslint-plugin": "4.16.1", "@typescript-eslint/parser": "4.16.1", "cordova-plugin-device": "^2.0.2", "cordova-plugin-ionic-keyboard": "^2.2.0", "cordova-plugin-ionic-webview": "^4.2.1", "cordova-plugin-splashscreen": "^5.0.2", "cordova-plugin-statusbar": "^2.4.2", "eslint": "^7.6.0", "eslint-plugin-import": "2.22.1", "eslint-plugin-jsdoc": "30.7.6", "eslint-plugin-prefer-arrow": "1.2.2", "jasmine-core": "~3.8.0", "jasmine-spec-reporter": "~5.0.0", "karma": "~6.3.2", "karma-chrome-launcher": "~3.1.0", "karma-coverage": "~2.0.3", "karma-coverage-istanbul-reporter": "~3.0.2", "karma-jasmine": "~4.0.0", "karma-jasmine-html-reporter": "^1.5.0", "protractor": "~7.0.0", "ts-node": "~10.9.1", "typescript": "~4.8.4" },


Solution

  • Changed in tsconfig.json from:

    "target": "es2020",

    into:

    "target": "es2015",

    and looks all works!