Search code examples
material-uistrict

Const declarations are not supported in strict mode on certain browsers


When I run my app in the iOS iPhone 6 simulator (or my physical iPad2) I get this error:

SyntaxError: Unexpected keyword 'const'. Const declarations are not supported in strict mode.
=> reactBoilerplateDeps.dll.js:4088 

Which leads to the is-in-browser module included by jss:

export const isBrowser = typeof window === "object"
    && typeof document === 'object'
    && document.nodeType === 9;

export default isBrowser;

I'm using these packages:

How do I correct this? Maybe the transform-es2015-block-scoping plugin as per this question ?

The app works fine on my physical iPhone 6 and desktop browser(s) but not on my iPad2.


Solution

  • According to Can I Use this is fixed in [iOS] Safari 10, so you might be able to get away with telling people who run into this issue that their browser isn't supported, and they should update it, but that's really not a good solution.

    Also, note that when twig.js hit this issue, their fix was to declare with the var keyword instead of const, so perhaps you should submit a bug report to is-in-browser about this.

    It would also be a good idea to try to see if using the var keyword instead of const works for you, by editing the file where you found export const isBrowser ... to replace const with var. This information will help if you decide to submit a bug report, and if it does work, you could create a fork of their repository with your fix, and submit a pull-request.