9

My app will not boot, it will break with the exception:

Invalid regular expression: invalid group specifier name

no stack
run
    NativeRunnable.java
handleCallback
    Handler.java:873
dispatchMessage
    Handler.java:99
dispatchMessage
    MessageQueueThreadHandler.java:29
loop
    Looper.java:209
run
    MessageQueueThreadImpl.java:232
run
    Thread.java:914

I found that in iOS or android, if I enabled live javascript debug, then the problem will not occur, but why?

The same error I got on xcode and android:

no stack', reason: 'Unhandled JS Exception: Invalid regular expression: invalid group specifier name

I have no idea where to dig? or where to debug? Any one can help?

simo
  • 23,342
  • 38
  • 121
  • 218
  • 1
    Have you tried looking closely at the regular expressions in your code? Perhaps one of them contains an [unsupported lookbehind](https://stackoverflow.com/questions/4200157/javascript-regular-expression-exception-invalid-group)? – Patrick Roberts Jul 14 '19 at 06:33
  • You are right, I have found it, although I was thinking that such error should occur once I enter the screen at which the regular expression used.. not at booting of app – simo Jul 14 '19 at 07:07
  • Regular expressions in JavaScript are compiled before the code is executed. Not sure why the discrepancy between development and production though, that might be related to what gets compiled into platform-specific code. – Patrick Roberts Jul 14 '19 at 07:11

2 Answers2

13

Ran into this as well, porting an electron project over to RN. Tracked it down to a lookbehind regular expression, which is supported in Chrome but not Safari (and, apparently, react native) -- see Works in Chrome, but breaks in Safari: Invalid regular expression: invalid group specifier name /(?<=\/)([^#]+)(?=#*)/

Searching for (? in my project led me right to the culprit!

lambinator
  • 10,616
  • 7
  • 55
  • 57
8

The reason you don't get a stack with this error is because regular expression literals in JavaScript are compiled before the script is executed.

Regular expression literals provide compilation of the regular expression when the script is loaded.

MDN - Regular Expressions

Unfortunately, this means that the offending regular expression might be anywhere in your code, since all the ES2015 modules are bundled together in react-native applications.

Community
  • 1
  • 1
Patrick Roberts
  • 49,224
  • 10
  • 102
  • 153