react-native: react-native start giving Invalid regular expression invalid error
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
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:
Describe what you expected to happen:
Was expecting it to bypass command successfully and app to run on android
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 57
- Comments: 73 (3 by maintainers)
Links to this issue
Commits related to this issue
- Fix blacklist regex syntax errors (#468) Summary: **Summary** On Windows with Node.js v12.x.x, Metro crashes with ``` SyntaxError: Invalid regular expression: /(.*\\__fixtures__\\.*|node_modules[\\\... — committed to facebook/metro by fson 5 years ago
- Updating the troubleshoot document For https://github.com/facebook/react-native/issues/26598 on windows. — committed to indranil32/react-native-website by indranil32 5 years ago
- Fix blacklist regex syntax errors (#468) Summary: **Summary** On Windows with Node.js v12.x.x, Metro crashes with ``` SyntaxError: Invalid regular expression: /(.*\\__fixtures__\\.*|node_modules[\\\... — committed to facebook/metro by fson 5 years ago
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
Same problem here. The following fixed it:
I solved the issue refer this https://iamsapankumar.blogspot.com/2019/10/error-invalid-regular-expression.html?m=1&fbclid=IwAR24kM7FvVFPR9ZTdq6HAmFDvF-Th7MnV2IvS3Yo_F9m6snDFh_QNsr0vgs
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.
+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:
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.
The solution *** uninstall react native and move to an actual stable platform.
I downgrade Node version:
choco install -y nodejs.install --version 10.16.3 --force
It’s still not fixed, why it’s closed?
Now instead of editing /node_modules you can add
resolutions
for metro-config inpackage.json
as temporary workaround:This issue should be reopened - following the documentation correctly leads to this failure, which means this is an open problem
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.
I downgrade Node version from 12.11.10 to the last stable version 10.16.3 LTS and it worked for me. Thanks @NyauIf
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!!
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.
Still hapenning with Node LTS 12.16.2, this should be fixed ASAP…
It’s still not fixed
12.8 works for the time being - separate issue #26808 opened about the same problem
This issue has been fixed as of #468 in metro.
@ThaJay @zaidpathanGit @soletan Just update
metro-react-native-babel-preset
to latest0.59.0
version and issue will be fixed. I’m on latestNodeJS 12.18.0
and react-native0.62.2
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.
Simplest steps to fix this for me were:
yarn install
React native setup is painful on win … i have stuck for 1 day for this problem.
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?
Hello everyone. I had the same problem and this is what I did to solve it thanks to @NyauIf :
choco uninstall nodejs.install
choco install nodejs-lts
cd project && react-native start
@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
For me changing the code into
node_modules\metro-config\src\defaults\blacklist.js
as per following worked.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…
I’m getting the same problem here.
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/./ ];
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/
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.
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: https://github.com/validatorjs/validator.js/issues/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.
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.
Downgrading to nodejs 10.18.1 did it for me.
This sucks…!!!
Only solution that worked for me was to downgrade node to the version of 12.9.1. Thanks! 😃
This is still very much an issue and should be reopened.
The mention of this fix should reach - http://facebook.github.io/react-native/docs/troubleshooting#content
Thanks!. Done and working
You can manually uninstall it using the
Control Panel
inWindows
and download whatever you want.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
How can is possible??? What can i do to uninstall and re-install?
Thanks!
@ahaq0 I am on Windows 10, what I did is the following:
react-native init appName --version="0.60.0"
node_modules\metro-config\src\defaults
there you will seeblacklist.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)react-native start
(to start a metro server)cd appName && react-native run-android
in the first terminal window@8bitpravibyte Try to remove
node_modules
and install it again or maybe try to useyarn
instead ofnpm i
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.
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,