launchdarkly / js-client-sdk

LaunchDarkly Client-side SDK for Browser JavaScript
Other
109 stars 62 forks source link

Safari v12 and v13 error for package versions 3.0.0 and above #267

Closed tylerexmg closed 1 year ago

tylerexmg commented 1 year ago

My project updated from npm package v2 to v3 and it is causing a breaking error in Safari 12 and 13.

image

Unfortunately I'm having a hard time debugging beyond this error to see exactly what the problem is. I just can confirm that using "launchdarkly-js-client-sdk": "^3.0.0" errors but "launchdarkly-js-client-sdk": "^2.24.2" does not.

yusinto commented 1 year ago

The LaunchDarkly JS SDK v3.0 and up uses optional chaining which is supported by modern browsers. It looks like you bundle your react app using webpack. The issue is webpack 4 uses a version of acorn which does not transpile the optional chaining operator. The solution as you can see in the react async provider example is to resolve the acorn package version that does support it. To do this, in your package.json file:

  "resolutions": {
    "acorn": "npm:acorn-with-stage3"
  }

Webpack 5 supports optional chaining out of the box so we recommend you upgrade to that if possible. If you use other bundlers, make sure to enable/include plugins for optional chaining for your bundler.

This is also covered in our v2 to v3 migration docs. Read more here.

tylerexmg commented 1 year ago

Hi @yusinto thank you for your reply. We are using Webpack 5 "webpack": "^5.73.0" and also use optional chaining in our code without issue when reverting to the LD JS SDK v2.

yusinto commented 1 year ago

This should be fixed in 3.1.1. We have removed the optional chaining operator so please update to that version if you have issues with the ? operator.