wanasit / chrono

A natural language date parser in Javascript
MIT License
4.57k stars 341 forks source link

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

Open l3utterfly opened 1 year ago

l3utterfly commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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

sanjeev-karat-zs0194 commented 11 months ago

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

nickdebaise commented 11 months ago

+1

elliscwc commented 11 months ago

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

wanasit commented 11 months ago

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)