chrono
chrono copied to clipboard
using with react-native: SyntaxError: Invalid RegExp: Invalid escape, js engine: hermes
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
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
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.
Do you know which version of Chrono being installed into your project? The locale specific import only available in v2.6.4 or later.
I'm using: "chrono-node": "^2.6.5"
Is there any fix for this? I am facing this one too. Am I missing something?
+1
If not mistaken, this is due to the use of \p{L}
and \p{N}
in those parsers
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)