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

后端 未结 19 2527
说谎
说谎 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:24

    This is caused by node v12.11.0 due to the way it deals regular location there two ways to solve this problem

    Method I

    You can downgrade to node v12.10.0 this will apply the correct way to deal with parsing error

    Method II

    You can correctly terminate the regular expression in you case by changing the file located a:

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

    A PR with a fix has been merged in the metro repository. Now we just need to wait until the next release. For now the best option is to downgrade to NodeJS v12.10.0. As Brandon pointed out, modifying anything in node_modules/ isa really bad practice and will not be a final solution.

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

    https://github.com/facebook/metro/issues/453

    for who still get this error without official patch in react-native , expo

    use yarn and add this setting into package.json

    {
      ...
      "resolutions": {
        "metro-config": "bluelovers/metro-config-hotfix-0.56.x"
      },
     ...
    
    0 讨论(0)
  • 2020-11-29 16:24

    All mentioned comments above are great, sharing the path that worked with me for this Blacklist file that need to be edited:

    "Your project name\node_modules\metro-bundler\src" File name "blacklist.js"

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

    As a general rule, I don't modify files within node_modules/ (or anything which does not get committed as part of a repository) as the next clean, build or update will regress them. I definitely have done so in the past and it has bitten me a couple of times. But this does work as a short-term/local dev fix until/unless metro-config is updated.

    Thanks!

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

    Go to

    \node_modules\metro-config\src\defaults\blacklist.js

    and replace this

    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 is not a best practice and my recommendation is: downgrade node version into 12.9 OR update metro-config since they are fixing the Node issue.

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