Skip to content

react-native start giving Invalid regular expression invalid error #26598

Closed

Description

@rohanpadwalkar

React Native version: 0.61

I followed following link to get started with react-native

Getting started with react native

I tried to create native app without expo so i as per documentation i followed following command

Steps To Reproduce

Initial commands

npm install -g react-native-cli
react-native init AwesomeProject

After run android command

react-native run-android 

It gave me following error on emulator
image

enter image description here

So i used start command to run metro server

react-native start

This command gave me another error in console

Snack, code example, screenshot, or link to a repository:
image

Describe what you expected to happen:

Was expecting it to bypass command successfully and app to run on android

Activity

  1. Coruscate5 commented on Oct 10, 2019

    @Coruscate5

    12.8 works for the time being - separate issue #26808 opened about the same problem

    choco uninstall nodejs
    choco install nodejs --version 12.8
    
  2. halkliff commented on Oct 10, 2019

    @halkliff

    Actually, the version 12.10.0 is the latest that works. Still, the regex is incorrect nonetheless, and the newer versions of node won't tolerate it anymore, so it needs to be fixed.

    It won't affect older versions, but surely will enable to be used in newer ones.

  3. momozizi commented on Oct 12, 2019

    @momozizi

    i had same problem:
    react-native start has error

    Invalid regular expression

    and after running react-native run-android my android device show me

    unable to load script. make sure you...

    then I tried to run choco unistall nodejd and run choco install nodejs-lts but react-native start has that error). so I run react-native info and result is:

    info Fetching system and libraries information...
    System:
    OS: Windows 7
    CPU: (8) x64 Intel(R) Core(TM) i7 CPU Q 740 @ 1.73GHz
    Memory: 925.38 MB / 3.98 GB
    Binaries:
    Node: 12.11.1 - C:\Program Files\nodejs\node.EXE
    npm: 6.11.3 - C:\Program Files\nodejs\npm.CMD
    SDKs:
    Android SDK:
    API Levels: 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29
    Build Tools: 25.0.0, 25.0.3, 26.0.0, 26.0.1, 26.0.2, 26.0.3, 27.0.3, 28.0.
    1, 28.0.2, 28.0.3, 29.0.1, 29.0.2
    System Images: android-25 | Google APIs Intel x86 Atom, android-28 | Googl
    e APIs Intel x86 Atom_64
    npmPackages:
    react: 16.9.0 => 16.9.0
    react-native: 0.61.2 => 0.61.2

    I could not find my answer.

  4. UK-Adam commented on Oct 22, 2019

    @UK-Adam

    Having the issue with the new lts version so previous fixes will no longer work (as with the current latest 13.0.0) . As halkliff said, the lts version is now changed to 12.13.0. Can get it to work if you get 10.16.3 from https://nodejs.org/dist/

  5. GrayYoung commented on Oct 23, 2019

    @GrayYoung

    Actually, the version 12.10.0 is the latest that works. Still, the regex is incorrect nonetheless, and the newer versions of node won't tolerate it anymore, so it needs to be fixed.

    It won't affect older versions, but surely will enable to be used in newer ones.

    Nodejs 12.13.0 still will cause this issue.

  6. JasonHughes94 commented on Oct 25, 2019

    @JasonHughes94

    Hey, as stated above with the release of Node 13 this had made the LTS now 12.13.0.
    You can revert back to 12.9.1 and this works as intended.

    Is there a plan on this being fixed for the latest versions of Node?

  7. FLGMwt commented on Oct 25, 2019

    @FLGMwt
    Contributor

    +1 on re-open, especially considering that the current LTS demonstrates this issue.

    As @JasonHughes94 mentioned, node 12.9.1 seems to be most recent version which does not demonstrate this error. Direct downloads for 12.9.1 can be found here: https://nodejs.org/download/release/v12.9.1/

    If you're using chocolatey, you can explicitly install this version with the following:

    choco install nodejs.install --version=12.9.1
    

    Since this ticket seems to have the most history and context, I think we could reopen this one and close the following:

    #26975
    #26969
    #26878
    #26829
    #26808

    This should be resolved once https://github.com/facebook/metro/pull/464/files is landed and RN is updated to point to the latest.

  8. armohammadi56 commented on Nov 1, 2019

    @armohammadi56

    It appears in \node_modules\metro-config\src\defaults\blacklist.js, there is an invalid regular expression that needed changed. I changed the first expression under sharedBlacklist from:

    var sharedBlacklist = [
    /node_modules[/\]react[/\]dist[/\]./,
    /website/node_modules/.
    /,
    /heapCapture/bundle.js/,
    /./tests/./
    ];

    to:

    var sharedBlacklist = [
    /node_modules[/\]react[/\]dist[/\]./,
    /website/node_modules/.
    /,
    /heapCapture/bundle.js/,
    /./tests/./
    ];

  9. friederbluemle commented on Nov 1, 2019

    @friederbluemle
    Contributor

    @armohammadi56 - After trying to spot the difference of the two code blocks for 2 minutes, I decided to throw them into text files and git diff --no-index them. Turned out there are no differences. 😂
    Looks like you accidentally copy+pasted the same. Can you edit your comment?

  10. halkliff commented on Nov 1, 2019

    @halkliff

    This issue has been fixed as of #468 in metro.

  11. EugeneDraitsev commented on Nov 2, 2019

    @EugeneDraitsev

    Now instead of editing /node_modules you can add resolutions for metro-config in package.json as temporary workaround:

      "resolutions": {
        "metro-config": "0.57.0"
      },
    
  12. 8bitpravibyte commented on Nov 13, 2019

    @8bitpravibyte

    I've downgraded to latest stable release 12.13.0, added resolutions section in package.json, runned npm install and still got the regex error.

  13. EugeneDraitsev commented on Nov 13, 2019

    @EugeneDraitsev

    @8bitpravibyte Try to remove node_modules and install it again or maybe try to use yarn instead of npm i

  14. 8bitpravibyte commented on Nov 13, 2019

    @8bitpravibyte

    @EugeneDraitsev Thanks man, it worked.
    I've deleted node_modules which were in C:\Users\Test\AppData\Roaming\npm\node_modules\react-native, because in my error the path for the blacklist.js file was this, installed react-native-cli again and used yarn to install them again.

  15. nahidmbstu commented on Nov 16, 2019

    @nahidmbstu

    React native setup is painful on win .... i have stuck for 1 day for this problem.

  16. ahaq0 commented on Nov 18, 2019

    @ahaq0

    Can you explain why this is a problem though?

  17. ahaq0 commented on Nov 18, 2019

    @ahaq0

    For the record I'm still getting it after doing everything suggested in this thread running on Windows 10.

  18. ahaq0 commented on Nov 18, 2019

    @ahaq0

    error Invalid regular expression: /(.\fixtures\.|node_modules[\]react[\]dist[\].|website\node_modules\.
    |heapCapture\bundle.js|.\tests\.
    )$/: Unterminated character class. Run CLI with --verbose flag for more detai
    ls.

  19. 8bitpravibyte commented on Nov 18, 2019

    @8bitpravibyte

    @ahaq0 I am on Windows 10, what I did is the following:

    1. react-native init appName --version="0.60.0"
    2. open windows explorer and find this path in your app dir node_modules\metro-config\src\defaults there you will see blacklist.js, you can open it and edit the sharedBlacklist variable (array with regexs) by removing all / (forward slash symbol) which are not in the begging or in the end of a row (if there are 4-5 rows of regex, you should leave there only the first and last forward slashes)
    3. open another terminal window and cd into the dir (appName) then react-native start (to start a metro server)
    4. cd appName && react-native run-android in the first terminal window
  20. 4D10S commented on Nov 20, 2019

    @4D10S

    Hi, i have the same problem when i execute

    react-native start

    I tried to follow the steps but i have a problem when i uninstall with choco!

    1º C:\WINDOWS\system32> node -v => v12.13.0
    2º choco uninstall nodejs

    Uninstalling the following packages:
    nodejs
    nodejs is not installed. Cannot uninstall a non-existent package.
    

    How can is possible??? What can i do to uninstall and re-install?

    Thanks!

  21. 8bitpravibyte commented on Nov 20, 2019

    @8bitpravibyte

    You can manually uninstall it using the Control Panel in Windows and download whatever you want.

  22. 4D10S commented on Nov 20, 2019

    @4D10S

    You can manually uninstall it using the Control Panel in Windows and download whatever you want.

    Thanks!. Done and working

  23. indranil32 commented on Nov 24, 2019

    @indranil32
  24. added a commit that references this issue on Nov 24, 2019
  25. SteveLockeUK commented on Nov 24, 2019

    @SteveLockeUK

    Simplest steps to fix this for me were:

    1. Install yarn
    2. Add resolution to package.json as per the comment from EugeneDraitsev above
    3. Delete the node_modules directory and the package-lock.json file (if present)
    4. run yarn install
  26. ThaJay commented on Nov 27, 2019

    @ThaJay

    Now instead of editing /node_modules you can add resolutions for metro-config in package.json as temporary workaround:

      "resolutions": {
        "metro-config": "0.57.0"
      },
    

    Thank you, this worked for me.

    It's too bad the metro devs were not aware of this issue in time but it's nice Yarn offers options to work around this semi-cleanly.

  27. surya0920 commented on Dec 2, 2019

    @surya0920

    Take a look at this hope this works for you:
    https://stackoverflow.com/questions/55441230/unable-to-load-script-make-sure-you-are-either-running-a-metro-server-or-that-yo?newreg=834f28d14a0f4de0b6928f6c875beeaf

    Go to this file: \node_modules\metro-config\src\defaults\blacklist.js and change this code:

    var sharedBlacklist = [
    /node_modules[/\]react[/\]dist[/\]./,
    /website/node_modules/.
    /,
    /heapCapture/bundle.js/,
    /./tests/./
    ];
    and change to this:

    var sharedBlacklist = [
    /node_modules[/\]react[/\]dist[/\]./,
    /website/node_modules/.
    /,
    /heapCapture/bundle.js/,
    /./tests/./
    ];

    This worked for me!!

  28. smakhtin commented on Dec 5, 2019

    @smakhtin

    It's still not fixed, why it's closed?

  29. BrandonBlanchard commented on Dec 5, 2019

    @BrandonBlanchard

    This is still very much an issue and should be reopened.

  30. Rananjaya commented on Dec 8, 2019

    @Rananjaya

    It's still not fixed

  31. aliahmedbd commented on Dec 8, 2019

    @aliahmedbd

    yes i am also facing this issues. actually Node.js Recommended For Most Users is version 10.16.3 LTS.
    Using below choco command will install Latest version of 12.11.0.
    choco install -y nodejs.install python2 jdk8

    I downgrade Node version from 12.11.0 to 10.16.3 LTS and it worked for me.

    It worked for me, thanks for the solution.

  32. ThaJay commented on Dec 11, 2019

    @ThaJay

    @smakhtin @BrandonBlanchard @Rananjaya I can advise you to read the topic. It is fixed and at some point the fix will land in your env. I agree it should have been fixed before it broke but these things happen. Metro devs are human just like the rest of us (I assume 😉).
    #26598 (comment)

  33. luk3skyw4lker commented on Dec 26, 2019

    @luk3skyw4lker

    I'm getting the same problem here.

  34. fatlun1981 commented on Dec 27, 2019

    @fatlun1981

    It appears in \node_modules\metro-config\src\defaults\blacklist.js, there is an invalid regular expression that needed changed. I changed the first expression under sharedBlacklist from:

    var sharedBlacklist = [
    /node_modules[/]react[/]dist[/]./, /website/node_modules/./,
    /heapCapture/bundle.js/,
    /./tests/./
    ];

    to:

    var sharedBlacklist = [
    /node_modules[/]react[/]dist[/]./, /website/node_modules/./,
    /heapCapture/bundle.js/,
    /./tests/./
    ];

    This work for me as well, but I have to change the express a bit:

    var sharedBlacklist = [
    /node_modules[\]react[\]dist[\]./,
    /website/node_modules/.
    /,
    /heapCapture/bundle.js/,
    /./tests/./
    ];

    I am on Windows 10, and using Anaconda.

  35. Mskirvk commented on Dec 28, 2019

    @Mskirvk

    +1 on re-open, especially considering that the current LTS demonstrates this issue.

    As @JasonHughes94 mentioned, node 12.9.1 seems to be most recent version which does not demonstrate this error. Direct downloads for 12.9.1 can be found here: https://nodejs.org/download/release/v12.9.1/

    If you're using chocolatey, you can explicitly install this version with the following:

    choco install nodejs.install --version=12.9.1
    

    Since this ticket seems to have the most history and context, I think we could reopen this one and close the following:

    #26975
    #26969
    #26878
    #26829
    #26808

    This should be resolved once https://github.com/facebook/metro/pull/464/files is landed and RN is updated to point to the latest.

    Only solution that worked for me was to downgrade node to the version of 12.9.1.
    Thanks! :)

  36. jcolon1984 commented on Dec 29, 2019

    @jcolon1984

    The solution *** uninstall react native and move to an actual stable platform.

  37. sonuame commented on Dec 29, 2019

    @sonuame

    This sucks..!!!

  38. sonuame commented on Dec 29, 2019

    @sonuame

    Setting it up to 12.9.1 worked

  39. yusufdonmez commented on Jan 1, 2020

    @yusufdonmez

    @ahaq0 I am on Windows 10, what I did is the following:

    1. react-native init appName --version="0.60.0"
    2. open windows explorer and find this path in your app dir node_modules\metro-config\src\defaults there you will see blacklist.js, you can open it and edit the sharedBlacklist variable (array with regexs) by removing all / (forward slash symbol) which are not in the begging or in the end of a row (if there are 4-5 rows of regex, you should leave there only the first and last forward slashes)
    3. open another terminal window and cd into the dir (appName) then react-native start (to start a metro server)
    4. cd appName && react-native run-android in the first terminal window

    changing blacklist.js file for '/' slashes is temporary solution. after adding new dependency or 'npm install' or 'yarn add' commands you have to do it again.

    I listen advives to downgrade nodeJS to 10.16.3 maybe 12.9.1 also works.( uninstall nodejs choco uninstall or windows program uninstall page, download versions from here whichever you want to try. ). I also init new project with optin --version="0.60.0" maybe just that worked for me. for my old projects I dont know what to do.

    I want permanent solution with a nodejs LTS release.

  40. douglas-pires commented on Jan 2, 2020

    @douglas-pires
    choco install nodejs.install --version=12.9.1
    

    This worked for me.

  41. sonuame commented on Jan 2, 2020

    @sonuame

    Instead of changing node version globally, I found "nodist" a better option for changing versions specific to projects.

    nodist local 12.9.1
    will do the magic

  42. aditodkar commented on Jan 4, 2020

    @aditodkar
  43. added a commit that references this issue on Jan 8, 2020
  44. leo-nerd commented on Jan 31, 2020

    @leo-nerd

    Downgrading to nodejs 10.18.1 did it for me.

  45. netgfx commented on Feb 8, 2020

    @netgfx

    downgraded to 12.9.1, via windows uninstall and getting a previous version from here: https://nodejs.org/download/release/v12.9.1/
    Terrible bug...

  46. soletan commented on Mar 9, 2020

    @soletan

    Downgrading is not an option if you really care for security. Believe or not, but sometimes newer versions of Node.js are fixing issues you should be concerned about.

    Is anyone capable of providing insights on why there is an invalid regular expression or why at least some parser isn't capable of adopting newer capabilities of distinguishing a forward slash inside a character class from a terminating forward slash? Please, provide details on why there are no upgrades for either involved dependency and why no one's caring on behalf of this project. Eventually this is just proving how error-prone this npm-style of coding is: don't use deps without checking whether they are implemented well enough for your tool. This ain't Lego. According to this thread I sincerely doubt react-native was ever made for lasting long enough to become a favourable platform for software meant to have its own LTS versions ...

    Don't downgrade. Otherwise consider downgrading to Windows XP or macOS 9 as well whenever your website does not look any good no more.

  47. herrera-ignacio commented on Apr 14, 2020

    @herrera-ignacio

    Still hapenning with Node LTS 12.16.2, this should be fixed ASAP...

  48. bbeckkk commented on May 17, 2020

    @bbeckkk

    None of the above solutions worked for me.

    So I deleted node from control panel and then install downgraded version
    choco install nodejs --version 12.8

    Now it is working.

  49. EnduIf commented on May 25, 2020

    @EnduIf

    A Fix should already be implemented react/metro#468

    Downgrading is not an option if you really care for security. Believe or not, but sometimes newer versions of Node.js are fixing issues you should be concerned about.

    Well you can try to upgreade to the newest Metro version, stop working or downgrade Node.Js.
    Its not like your App uses Node.Js

  50. soletan commented on May 25, 2020

    @soletan

    Well you can try to upgreade to the newest Metro version, stop working or downgrade Node.Js.
    Its not like your App uses Node.Js

    I'm pretty aware of Node.js not involved in running my app, but it is essential to processing several 100.000+ files for building it. Do you trust all the modules involved in building your application for they are provided by a plethora of different vendors? Do you expect all those files to be free of any vulnerability at any time? Do you believe that neither such vulnerability at build time could affect your application's integrity at runtime?

  51. ThaJay commented on May 29, 2020

    @ThaJay

    @soletan If the fix is upstream we can only wait for the release or run straight from the repo. I do agree this fix could have been done a while ago.

  52. zaidpathanGit commented on Jun 11, 2020

    @zaidpathanGit

    For me changing the code into node_modules\metro-config\src\defaults\blacklist.js as per following worked.

    var sharedBlacklist = [
    //node_modules[/\]react[/\]dist[/\]./,
    //website/node_modules/./,
    //heapCapture/bundle.js/,
    //./tests/./
    ];
    
  53. oleksandr-dziuban commented on Jun 11, 2020

    @oleksandr-dziuban

    @ThaJay @zaidpathanGit @soletan
    Just update metro-react-native-babel-preset to latest 0.59.0 version and issue will be fixed.
    I'm on latest NodeJS 12.18.0 and react-native 0.62.2

  54. Sid-Shanker commented on Jun 12, 2020

    @Sid-Shanker

    @ThaJay @zaidpathanGit @soletan
    Just update metro-react-native-babel-preset to latest 0.59.0 version and issue will be fixed.
    I'm on latest NodeJS 12.18.0 and react-native 0.62.2

    This worked for me. I updated metro-react-native-babel-preset from 0.51.1 to 0.59.0, and i am using react-native version 0.61.3. npm install and audit fix if needed.

  55. kp47 commented on Jun 12, 2020

    @kp47

    I have this issue. I tried to run the app using different node versions by upgrading and downgrading node but none of them worked.

    I get Unhandled JS Exception: Invalid regular expression: Invalid group specifier name.

    Any help would be great

  56. stage88 commented on Jun 13, 2020

    @stage88

    Spent a day looking at this, for me nothing mentioned above helped, I checked all packages for upgraded and it turned out to be an issue with 'validator' package, see this issue: validatorjs/validator.js#1354

    Edit: also I should say that in debug it was all fine, however as soon as I built in release mode and deployed on a device, I got this error.

  57. profnandaa commented on Jun 27, 2020

    @profnandaa

    Validator issue mentioned was fixed long ago from our end; let me know if you are still blocked on this.

  58. yashwant-dangi commented on Aug 1, 2020

    @yashwant-dangi

    This should be fixed

  59. Mitchell-Stone commented on Sep 21, 2020

    @Mitchell-Stone

    I get this error on following the react-360 introductory steps.

    Invalid regular expression: /(node_modules[\]react[\]dist[\].|website\node_modules\.|heapCapture\bundle.js|.\tests\.)$/: Unterminated character class

    Node version 12.18.4.

    Doesn't instill confidence when you can't run the default app supplied for an example.

  60. profnandaa commented on Sep 21, 2020

    @profnandaa

    @Mitchell-Stone -- can you post a bit detailed error log?

  61. Mitchell-Stone commented on Sep 23, 2020

    @Mitchell-Stone

    @profnandaa
    I found that changing the blacklist var worked:
    var sharedBlacklist = [ /node_modules[\/\\]react[\/\\]dist[\/\\].*/, /website\/node_modules\/.*/, /heapCapture\/bundle\.js/, /.*\/__tests__\/.*/ ];

    I did this in the metro-config file

  62. locked as resolved and limited conversation to collaborators on Oct 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugRan CommandsOne of our bots successfully processed a command.Resolution: LockedThis issue was locked by the bot.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions