react-native start giving Invalid regular expression invalid error

user4241989 picture user4241989 · Sep 26, 2019 · Viewed 14.8k times · Source

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

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

enter image description here

Answer

Javier C. picture Javier C. · Nov 12, 2019

There are a problem with Metro using some NPM and Node versions.

You hay 2 alternatives:

  • Alternative 1: Uninstall node and npm and reinstall with another versions.
  • Alternative 2: Hot to 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__\/.*/
];

to this:

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

Please note that if you run an npm install or a yarn install you need to change the code again.