react-native start giving Invalid regular expressi

2020-05-26 04:00发布

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

10条回答
女痞
2楼-- · 2020-05-26 04:20

A similar question was asked here may be this solution might work for you cause i applied and it worked

查看更多
地球回转人心会变
3楼-- · 2020-05-26 04:22

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.

查看更多
【Aperson】
4楼-- · 2020-05-26 04:23

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

查看更多
在下西门庆
5楼-- · 2020-05-26 04:32

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.

查看更多
神经病院院长
6楼-- · 2020-05-26 04:36

close Commands prompt and metro bundler,do it again

查看更多
霸刀☆藐视天下
7楼-- · 2020-05-26 04:39

yeah, just shift to Node version 10 and it will work.

nvm install <version>
nvm use <version>

it works...... :)

查看更多
登录 后发表回答