chrono icon indicating copy to clipboard operation
chrono copied to clipboard

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

Open l3utterfly opened this issue 1 year ago • 8 comments

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

l3utterfly avatar Aug 14 '23 15:08 l3utterfly

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

wanasit avatar Aug 20 '23 03:08 wanasit

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.

l3utterfly avatar Aug 28 '23 07:08 l3utterfly

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

wanasit avatar Sep 03 '23 05:09 wanasit

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

l3utterfly avatar Sep 13 '23 11:09 l3utterfly

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

sanjeev-karat-zs0194 avatar Nov 14 '23 17:11 sanjeev-karat-zs0194

+1

nickdebaise avatar Nov 14 '23 18:11 nickdebaise

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

elliscwc avatar Nov 15 '23 15:11 elliscwc

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)

wanasit avatar Nov 19 '23 05:11 wanasit