Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EMOJI_REGEX throws Invalid regular expression flags on node v18 #599

Closed
AlexXanderGrib opened this issue May 24, 2024 · 4 comments
Closed
Assignees
Labels
question Further information is requested

Comments

@AlexXanderGrib
Copy link

Hello, the following line breaks projects running on node 18

export const EMOJI_REGEX = /^\p{RGI_Emoji}+$/v;

Node js 18 does not support regex /v flag so node throws an error

SyntaxError: Invalid regular expression flags 

Easy fix:

export const EMOJI_REGEX = (() => { 
  try { 
    return new RegExp('^\\p{RGI_Emoji}+$', 'v'); 
  } catch { 
    return /^[\p{Extended_Pictographic}\p{Emoji_Component}]+$/u; 
  } 
})();
@fabian-hiller
Copy link
Owner

The bigger question is whether we should stick with the current code and force people to upgrade to Node.js v20. I don't plan to implement a try/catch workaround, but I can consider not using this feature until v2 of Valibot to give devs more time.

@fabian-hiller fabian-hiller self-assigned this May 24, 2024
@fabian-hiller fabian-hiller added the question Further information is requested label May 24, 2024
@AlexXanderGrib
Copy link
Author

I advise keeping the old way.

  1. Node.JS 18 support ends 30 Apr 2025
  2. Because valibot is smallest validation library, its best to bring to frontend (ex. form validation), and /v flag has compatibility issues with safari. It's supported only on safari >= 17(source)
  3. Regex syntax errors are painful to debug. I found cause of this issue randomly downgrading dependencies, because nuxt provided no stack trace

Also, you can how check ufo handled similar issue with regex unjs/ufo#224

@fabian-hiller
Copy link
Owner

Thanks for your research! Since this regex is not too important, I think I will follow your recommendation.

@fabian-hiller
Copy link
Owner

This is fixed in v0.31.0-rc.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants