2
votes

On Android 6 Marshmallow it works fine when apk build But gives error at "selector:" codeline in Android Lollipop

Error :

Uncaught SyntaxError: Unexpected token ILLEGAL in main.js warning : "The key "viewport-fit" is not recognized and ignored"

I don't know what is wrong.

 `HomePage = __decorate([
        Object(__WEBPACK_IMPORTED_MODULE_0__angular_core__["m" /* Component */])({
            selector: 'page-home',template:/*ion-inline-start:"D:\2fb\src\pages\home\home.html"*/`\n  \n    \n      Facebook\n    \n  \n\n\n\n  \n    Facebook Login Example\n  \n\n  \n    Log In with Facebook\n  \n\n  \n    \n    \n      \n        {{ userProfile.displayName }}\n      \n      

\n The UID for this new user is {{userProfile.uid}} and the email is {{userProfile.email}}\n

\n \n \n`/*ion-inline-end:"D:\2fb\src\pages\home\home.html"*/ }), __metadata("design:paramtypes", [__WEBPACK_IMPORTED_MODULE_2_ionic_angular__["d" /* NavController */], __WEBPACK_IMPORTED_MODULE_1__ionic_native_facebook__["a" /* Facebook */]]) ], HomePage);`
1
what version of ionic you are using?Prerak Tiwari
same here! ionic version 3.9.2g bas
One workaround is to add crosswalk. Maybe your android device uses an incompatible.g bas

1 Answers

0
votes

I had similar issue using 3.9.2 when deployed to Android 4.4.4. The possible reason is the template string embraced with ` (ASCII 96) not common single quotation marks (ASCII 39).

My ugly fix is to replace ` with ' by using after prepare script as follows:

#!/usr/bin/env node

var fs = require('fs');
var path = require('path');

var rootdir = process.argv[2] + '/../';

function replace_string_in_file(filename, to_replace, replace_with) {
  var data = fs.readFileSync(filename, 'utf8');

  var result = data.replace(new RegExp(to_replace, "g"), replace_with);
  fs.writeFileSync(filename, result, 'utf8');
}

var target = "dev";
if (process.env.TARGET) {
  target = process.env.TARGET;
}

var replaceConfig = {
  "platforms/android/assets/www/build/main.js" : {
    "dev": {
      "/`": "/'",
      "`/": "'/"
    }
  }
};
for (var filename in replaceConfig) {
  var fullFilename = path.join(rootdir, filename);
  if (fs.existsSync(fullFilename)) {
    var replaceTexts = replaceConfig[filename];
    for (var key in replaceTexts[target]) {
      console.log(target + " replacing in file: " + fullFilename + " " + key + " as " + replaceTexts[target][key]);
      replace_string_in_file(fullFilename, key, replaceTexts[target][key]);
    }
  } else {
    console.log("missing: " + fullFilename);
  }
}

It fixes my problem. Hope this helps.