Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
rohanpadwalkar opened this issue Sep 26, 2019 · 73 comments
Closed
Labels
Bug Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot.

Comments

@rohanpadwalkar
Copy link

rohanpadwalkar commented Sep 26, 2019

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

@react-native-bot
Copy link
Collaborator

Thanks for submitting your issue. Can you take another look at your description and make sure the issue template has been filled in its entirety?

👉 Click here if you want to take another look at the Bug Report issue template.

@react-native-bot react-native-bot added Ran Commands One of our bots successfully processed a command. Resolution: Needs More Information labels Sep 26, 2019
@rohanpadwalkar
Copy link
Author

Node : v12.11.0
Npm: 6.11.3
Python: 2.7.16

@EnduIf
Copy link

EnduIf commented Sep 27, 2019

Try to downgrade your Node version.
I've had the same issue after I upgraded from v12.8 => v12.11
After the downgrade it works again

@robstermarinho
Copy link

I downgrade Node version from 12.11.10 to the last stable version 10.16.3 LTS and it worked for me.
Thanks @NyauIf

@senthilkumar3282
Copy link

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.

@dibya-89
Copy link

Just downgrade the Node version it will work fine.
Best way to use https://github.com/nvm-sh/nvm
it helps to change the node version as required,

@friederbluemle
Copy link
Contributor

Same problem here. The following fixed it:

choco uninstall nodejs
choco install nodejs-lts

@ricardo-morgilli
Copy link

I downgrade Node version:
choco install -y nodejs.install --version 10.16.3 --force

@rohanpadwalkar
Copy link
Author

downgrading Node version worked for me.

Thanks everyone for help.

@halkliff
Copy link

halkliff commented Oct 7, 2019

They should be working on compatibility with node 12 though, the 10.16.3 LTS node is going to be replaced by Node 12 in Oct. 22, 2019.

@Coruscate5
Copy link

This issue should be reopened - following the documentation correctly leads to this failure, which means this is an open problem

@Coruscate5
Copy link

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

choco uninstall nodejs
choco install nodejs --version 12.8

@halkliff
Copy link

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.

@momozizi
Copy link

momozizi commented Oct 12, 2019

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.

@efranelas
Copy link

efranelas commented Oct 13, 2019

Hello everyone. I had the same problem and this is what I did to solve it thanks to @NyauIf :

  1. Uninstalled version v12.11:
    choco uninstall nodejs.install
  2. Installed long-term support version v10.16.3:
    choco install nodejs-lts
  3. Started metro server:
    cd project && react-native start

@UK-Adam
Copy link

UK-Adam commented Oct 22, 2019

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/

@GrayYoung
Copy link

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.

@JasonHughes94
Copy link

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?

@FLGMwt
Copy link
Contributor

FLGMwt commented Oct 25, 2019

+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.

This was referenced Oct 25, 2019
@sonuame
Copy link

sonuame commented Dec 29, 2019

Setting it up to 12.9.1 worked

@yusufdonmez
Copy link

@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.

@douglas-pires
Copy link

choco install nodejs.install --version=12.9.1

This worked for me.

@sonuame
Copy link

sonuame commented Jan 2, 2020

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

@aditodkar
Copy link

I solved the issue refer this https://iamsapankumar.blogspot.com/2019/10/error-invalid-regular-expression.html?m=1&fbclid=IwAR24kM7FvVFPR9ZTdq6HAmFDvF-Th7MnV2IvS3Yo_F9m6snDFh_QNsr0vgs

@j0k3r87
Copy link

j0k3r87 commented Jan 4, 2020

cpojer pushed a commit to facebook/metro that referenced this issue Jan 8, 2020
Summary:
**Summary**

On Windows with Node.js v12.x.x, Metro crashes with
```
SyntaxError: Invalid regular expression: /(.*\\__fixtures__\\.*|node_modules[\\\]react[\\\]dist[\\\].*|website\\node_modules\\.*|heapCapture\\bundle\.js|.*\\__tests__\\.*)$/: Unterminated character class
```
This has been reported in #453, facebook/react-native#26829, facebook/react-native#26969, facebook/react-native#26878, facebook/react-native#26598, expo/expo-cli#1147 and expo/expo-cli#1074.

There are a few open pull requests attempting to fix this same issue:
* #464
* #461
* #458
* #454

However, none of the existing PRs address the *root cause* of this error: the `escapeRegExp` function in `blacklist.js` tries to convert regular expressions to be agnostic to the path separator ("/" or "\\"), but turns some valid regular expressions to invalid syntax.

The error was is this line:
https://github.com/facebook/metro/blob/142348f5345e40ce2075fc7f9dfa30c5d31fee2a/packages/metro-config/src/defaults/blacklist.js#L28
When given a regular expression, such as `/node_modules[/\\]react[/\\]dist[/\\].*/`, on Windows where `path.sep` is `\` (which is also an escape character in regular expressions), this gets turned into `/node_modules[\\\]react[\\\]dist[\\\].*/`, resulting in the `Unterminated character class` error.

Automatically replacing `[/]` with `[\]` is an error, as is replacing `[\/]` with `[\\]`, because in both of these cases the backslash before the end of character class "]" escapes it, and the character class becomes unterminated. Therefore, this PR changes the code to look for both escaped forward slash `\/` and forward slash `/`, and always replace them with the escaped version (`\/` or `\\`, depending on the platform).

This fixes #453.

**Test plan**

Added a test case that exercises the code with both `\` and `/` as path separators.
Pull Request resolved: #468

Differential Revision: D18201730

Pulled By: cpojer

fbshipit-source-id: 6bb694178314c39d4d6a0fd9f8547bfa2c36f894
@rodrigogsn
Copy link

@leo-nerd
Copy link

Downgrading to nodejs 10.18.1 did it for me.

@netgfx
Copy link

netgfx commented Feb 8, 2020

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...

@soletan
Copy link

soletan commented Mar 9, 2020

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.

@herrera-ignacio
Copy link

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

@bbeckkk
Copy link

bbeckkk commented May 17, 2020

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.

@EnduIf
Copy link

EnduIf commented May 25, 2020

A Fix should already be implemented facebook/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

@soletan
Copy link

soletan commented May 25, 2020

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?

@ThaJay
Copy link

ThaJay commented May 29, 2020

@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.

@zaidpathanGit
Copy link

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/./
];

@oleksandr-dziuban
Copy link

@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

@Sid-Shanker
Copy link

@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.

@kp47
Copy link

kp47 commented Jun 12, 2020

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

@stage88
Copy link

stage88 commented Jun 13, 2020

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.

@profnandaa
Copy link

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

@yashwant-dangi
Copy link

This should be fixed

@Mitchell-Stone
Copy link

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.

@profnandaa
Copy link

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

@Mitchell-Stone
Copy link

Mitchell-Stone commented Sep 23, 2020

@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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests