SyntaxError: Use of const in strict mode

I import a javascript file in my ionic2 app in this way,
> import WSPlayer from './assets/js/rtsp_player';
In the browser anything is working fine, but run the same code on android emulator I get this error:

Runtime Error
Use of const in strict mode.
Stack
SyntaxError: Use of const in strict mode.

I’m not sure if I should use the crosswalk browser to resolve this issue, and if this is the only way to resolve it?

@mburger81 Could you fix this issue?

I had a similar issue, created by my own code. I found it using genymotion emulator and chrome://inspect which directed me to the right line in main.js.

I had a file which I import in the code:

export const MENU_SECTIONS = { HOME: 'HOME', GIFT: 'GIFT', FAVOURITES: 'FAVOURITES', ACCOUNT: 'ACCOUNT', SETTINGS: 'SETTINGS', SHOP: 'SHOP', SUPPORT: 'SUPPORT', ABOUT: 'ABOUT', LOGOUT: 'LOGOUT' };

Replacing with this code solved the issue:

export const Global = Object.freeze({
  MENU_SECTIONS : {
    HOME:          'HOME',
    GIFT:          'GIFT',
    FAVOURITES:    'FAVOURITES',
    ACCOUNT:       'ACCOUNT',
    SETTINGS:      'SETTINGS',
    SHOP:          'SHOP',
    SUPPORT:       'SUPPORT',
    ABOUT:         'ABOUT',
    LOGOUT:        'LOGOUT'
  },
});

I’m just going to reiterate my opinion that const in JavaScript is less than worthless.

Hi chris08002, no we are still using crosswalk browser to resolve this. No idea if something changed in the last months.

You are right man, but what should we do if we use three very very big and very very big javascript libs for video decoding and others, where they use CONST and for sure we would not and could not change this, test this and mantain this.
Probably we can remove only CONST but we try to not fork any lib.

IMO
thx

That’s cool, I just don’t want people seeing this, thinking const is of any value whatsoever, and using it in their own code. All it provides is a false sense of security, which is why I consider it “worse than useless”.

@rapropos It’s distracting from this thread a bit, but what would you suggest to use for global values (“constants”) that we want to set throughout an angular/ionic app. Like for the “export const Global” as above?

If I really want to make sure it can’t be modified, I use functions:

export function totallyImmutable(): string {
  return "can't touch this";
}
1 Like

It seems using app-scripts 3.0 we are able to use es6 and es7 javascript files into the project and can bundle it with --prod flag!