How to resolve the error on 'react-native start'

后端 未结 19 2524
说谎
说谎 2020-11-29 15:41
  1. I just installed node.js & cli

    • installed node.js
    • installed react-native-cli

      npm -g react-native-cli
      
相关标签:
19条回答
  • 2020-11-29 16:00

    [Quick Answer]

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

    You can fix the problem changing some code in the file \node_modules\metro-config\src\defaults\blacklist.js .

    Search this variable:

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

    and change 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.

    0 讨论(0)
  • 2020-11-29 16:00

    I had the same problem I altered the E:\NodeJS\ReactNativeApp\ExpoTest\node_modules\metro-config\src\defaults\blacklist.js in my project

    from

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

    to

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

    this worked perfectly for me

    0 讨论(0)
  • 2020-11-29 16:00

    The use of yarn prevents this situation. Yarn should use

    0 讨论(0)
  • 2020-11-29 16:02

    The solution is simple, but temporary...

    Note that if you run an npm install or a yarn install you need to change the code again!

    So, how can we run this automatically?

    Permanent Solution

    To do this "automagically" after installing your node modules, you can use patch-package.

    1. Fix the metro-config file, solving the error:

    The file appears in \node_modules\metro-config\src\defaults\blacklist.js.

    Edit from:

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

    To:

    var sharedBlacklist = [
      /node_modules[\/\\]react[\/\\]dist[\/\\].*/,
      /website\/node_modules\/.*/,
      /heapCapture\/bundle\.js/,
      /.*\/__tests__\/.*/
    ];
    
    1. Then, generate a permanent patch file:

    npx patch-package metro-config

    1. In your package.json trigger the patch:
    "scripts": {
    +  "postinstall": "npx patch-package"
    }
    

    All done! Now this patch will be made at every npm install / yarn install.

    Thanks to https://github.com/ds300/patch-package

    0 讨论(0)
  • 2020-11-29 16:05

    You have two solutions:

    either you downgrade node to V12.10.0 or you can modify this file for every project you will create.

    node_modules/metro-config/src/defaults/blacklist.js Change this:

    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__\/.*/
    ];
    
    0 讨论(0)
  • 2020-11-29 16:07

    I got same problem.

    "error Invalid regular expression: /(.\fixtures\.|node_modules[\]react[\]dist[\].|website\node_modules\.|heapCapture\bundle.js|.\tests\.)$/: Unterminated character class."

    Change the regular expression in \node_modules\metro-config\src\defaults\blacklist.js

    From

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

    To

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

    This change resolved my error.

    0 讨论(0)
提交回复
热议问题