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

using with react-native: SyntaxError: Invalid RegExp: Invalid escape, js engine: hermes #527

Open
l3utterfly opened this issue Aug 14, 2023 · 8 comments

Comments

@l3utterfly
Copy link

Giving the error: SyntaxError: Invalid RegExp: Invalid escape, js engine: hermes when parsing simple string:

let prompt = '2 hours';

let eventDate = chrono.parseDate(prompt);
console.log(eventDate);

Using latest react-native: 0.72.4

Can be fixed by commenting out "uk", "zh", and "ru" parsers in ./chrono-node/dist/cjs/index.js

@wanasit
Copy link
Owner

wanasit commented Aug 20, 2023

Thanks for reporting this.

We had a similar problem with Hermes engine's RegEx in #483. I thought it should have already been fixed in more recent versions. I would need some more time to setup React Native env to debug and fix this.

In the meantime, if you do not use those locale, could you try import only English or other locales that you use?

See: https://github.com/wanasit/chrono#importing-specific-locales

@l3utterfly
Copy link
Author

Thanks for your reply. I tried this in React Native: import * as chrono from 'chrono-node/en'; It just says module chrono-node/en is not found.

@wanasit
Copy link
Owner

wanasit commented Sep 3, 2023

Do you know which version of Chrono being installed into your project?
The locale specific import only available in v2.6.4 or later.

@l3utterfly
Copy link
Author

I'm using: "chrono-node": "^2.6.5"

@sanjeev-karat-zs0194
Copy link

Is there any fix for this? I am facing this one too. Am I missing something?

@nickdebaise
Copy link

+1

@elliscwc
Copy link

If not mistaken, this is due to the use of \p{L} and \p{N} in those parsers

@wanasit
Copy link
Owner

wanasit commented Nov 19, 2023

Sorry for my slow response. Please try update to Chrono v2.7.3
https://github.com/wanasit/chrono/releases/tag/v2.7.3

(As @elliscwc also mentioned) RegEx patterns in Russian and Ukrainian parsers are not supported by Hermes Engine. I have fixed the issue by switching to lazy-loading/creating RegEx patterns. (Also note that chrono.uk and chrono.ru are not usable)

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

No branches or pull requests

5 participants