bjoluc / next-redux-cookie-wrapper

Sync a subset of your Redux state with cookies in Next.js :cookie: :sparkles:
MIT License
114 stars 4 forks source link

Error: Unexpected token "=", on Safari (=< 13.1) #45

Closed QuentinCharlie closed 1 year ago

QuentinCharlie commented 1 year ago

Hello there,

Using your ^2.2.0 version, i got the error screenshoted below on older safari (from 14.1 it works fine). I don't have the error with your 2.1.2 version tho.

image

I guess it's related to this https://stackoverflow.com/questions/60026651/safari-unexpected-token-expected-an-opening-before-a-methods-paramet

bjoluc commented 1 year ago

Hi @QuentinCharlie,

thanks for flagging this! It might have been my mistake when migrating from tsdx to tsup: I set the target option to node12, thinking that Next.js would transpile everything anyway. Now I'm not sure about that anymore, let me check...

bjoluc commented 1 year ago

I wasn't wrong, it does :tada: So this is not a config thing in next-redux-cookie-wrapper, luckily. Next.js targets Safari 12+ by default. Which version did you try?

QuentinCharlie commented 1 year ago

Thanks for the quick response. You meant the Next.js version we use ? It's the 12.3.0.

bjoluc commented 1 year ago

Sorry for not being clear, I meant the Safari version, given that Savari >= 12 should be supported (at least in latest Next.js). Did you try explicitly setting a browserslist config like defaults, Safari >= 11 in your package.json?

Closing this issue since transpiling production code for outdated browsers is up to Next.js/Babel :slightly_smiling_face:

QuentinCharlie commented 1 year ago

It was for all Safari versions =<13.1 yes, i tried different ones, regardless of my browerslist config (including the one you said while running 12.1). It's only when i run the 2.1.2 version of your package that my application works on those older safari versions (even without browserslist config btw).

bjoluc commented 1 year ago

Well, that's annoying. Out of curiosity, if you put

class Foo {
  bar = 0;
}
new Foo();

into one of your project's files, you would get the same error, right? Does manually adding @babel/plugin-proposal-class-properties in a custom babel config change anything?

QuentinCharlie commented 1 year ago

Adding the Foo code doesn't trigger any error and seems to works fine. (I can display the bar value on the app).

I tried to add a custom babel config to see if it solved the main issue, but sadly doesn't.

bjoluc commented 1 year ago

Any chance you can find out what causes the syntax error in next-redux-cookie-wrapper?

QuentinCharlie commented 1 year ago

The error in console, and where it is pointing at :

image image

I also cloned your repo and tested the demo, to see if somehow my application could be a vector of the issue, but i have the same problem (working fine except for those same older safari versions).

bjoluc commented 1 year ago

Does it make any difference when you change the target in main/package.json to

    "target": [
      "node12",
      "safari11"
    ],

and run npm run build -w main?

QuentinCharlie commented 1 year ago

Seems to works !

Also did just to be sure :

Works like a charm :clap:

bjoluc commented 1 year ago

Next.js v12.3.0 (just like latest v13) uses @swc/core@1.2.203. The next step should be to check what causes the syntax error and if it was fixed in @swc/core by now – I couldn't find any existing SWC issues on it. I can't research this myself, unfortunately, since I don't have access to Safari and don't know which exact syntax causes it. If you have some time available, please feel free to file an upstream issue.

Anyway, since fixing things upstream may take some time, LMK if you'd like me to publish a patch release of next-redux-cookie-wrapper for the time being.