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:
- Install Replace-in-file module:
npm install --save replace-in-file
Create a file at the same level as
node_module
folder name it:metro-fix.js
per example.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);
}
- 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
oryarn install
you'll need to change the code again.