react-native start giving Invalid regular expression invalid error

Its compatibility issue of Nodejs I uninstalled my Node(12.11) and installed Node(10) stable version and it worked perfectly.


The solution is to change the blacklist.js file in module metro-config files as answered above. But each time you run npm/yarn install you will have to change it again.

So I came up with a solution that will save you time form going to the file and changing it each time:

I used a library that edit files using JavaScript:

  1. Install Replace-in-file module:
npm install --save replace-in-file
  1. Create a file at the same level as node_module folder name it: metro-fix.js per example.

  2. Copy paste this script in it:

//Load the library
const replace = require('replace-in-file');
// path for metro config file
const path = 'node_modules/metro-config/src/defaults/blacklist.js';
// creating options for editing the file
const options = [
  {
    files: path,
    from: 'modules[/',
    to: 'modules[\\/',
  },
  {
    files: path,
    from: 'react[/',
    to: 'react[\\/',
  },
  {
    files: path,
    from: 'dist[/',
    to: 'dist[\\/',
  },
];

try {
  let results;
  // looping on each option
  options.forEach(e => {
    results = replace.sync(e);
    console.log('Replacing "'+e.from+'" by "'+e.to+'"  results:', results[0].hasChanged);
  });

} catch (error) {
  console.error('Error occurred:', error);
}
  1. Now each time you run npm install just run:
node metro-fix.js

See Replace-in-file docs.


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

You hay 2 alternatives:

  • Alternative 1: Uninstall node and npm and reinstall with another (compatible) version: https://nodejs.org/en/download

  • Alternative 2: Go to a file in your npde_modules folder: \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 npm install or yarn install you'll need to change the code again.