react-native start giving Invalid regular expression invalid error

一曲冷凌霜 提交于 2020-02-26 09:15:10

问题


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

So i used start command to run metro server

react-native start

This command gave me another error in console


回答1:


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.




回答2:


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




回答3:


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




回答4:


When you install the NodeJS using the choco command(choco install -y nodejs.install python2 jdk8), it will install the latest version of node which is 12.12.0 at the time of writing this answer. You have to downgrade it to 10.16.3 and run the react-native run-android command and it should work fine




回答5:


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

nvm install <version>
nvm use <version>

it works...... :)




回答6:


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.




回答7:


close Commands prompt and metro bundler,do it again




回答8:


I solved this issue with this step :

  1. Uninstall node v12 and install node v8.9.4
  2. re-install react-native-cli
  3. re-create project react-native init myApp --version 0.60.0
  4. react-native start

Hope it helps




回答9:


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.




回答10:


It is because of the node version is higher.

  1. One of the solutions is that you can easily downgrade the node version from 12.x to 10.x or uninstall 12.x and install 10.x

  2. On the other hand what if you want to use 12.x for some other project. So the below solution makes it easier. You can nvm which can control the multiple versions of node.

So first install nvm from here https://github.com/coreybutler/nvm-windows/releases

Once installed remember to add the nvm path to system variable

then nvm install 10.18.1 64

then nvm install 12.14.1 64

to list all the versions installed nvm list

whenever you want to switch from one version to another version use the command

nvm use 10.18.1  OR nvm use 12.14.1


来源:https://stackoverflow.com/questions/58117377/react-native-start-giving-invalid-regular-expression-invalid-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!