如何解决'react-native start'的错误 [英] How to resolve the error on 'react-native start'

查看:56
本文介绍了如何解决'react-native start'的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  1. 我刚刚安装了 node.js &剪辑

    • 已安装 node.js
    • 安装 react-native-cli

      npm -g react-native-cli

  2. 并创建了一个新项目".

    react-native init new_project

  3. 在那个 'new_project' 目录中,我很想看看 Metro bundler 是否运行良好.

    react-native start

  4. 但是命令给了我以下错误并且地铁没有启动.修复此错误的任何线索?(我使用的是 Windows 10 操作系统.)

    • 命令:C:\projects\new_proj>react-native start<块引用>

      错误正则表达式无效:/(.\fixtures.|node_modules[]react[]dist[].|website\node_modules.|heapCapture\bundle.js|.\tests.)$/:未终止的字符类.使用 --verbose 标志运行 CLI 以获取更多详细信息.语法错误:无效的正则表达式:/(.\fixtures.|node_modules[]react[]dist[].|website\node_modules.|heapCapture\bundle.js|.\tests.)$/:未终止的字符类在新的正则表达式 ()在黑名单 (D:\projects\new_proj\node_modules\metro-config\src\defaults\blacklist.js:34:10)在 getBlacklistRE (D:\projects\new_proj\node_modules\react-native\node_modules@react-native-community\cli\build\tools\loadMetroConfig.js:69:59)在 getDefaultConfig (D:\projects\new_proj\node_modules\react-native\node_modules@react-native-community\cli\build\tools\loadMetroConfig.js:85:20)在负载 (D:\projects\new_proj\node_modules\react-native\node_modules@react-native-community\cli\build\tools\loadMetroConfig.js:121:25)在 Object.runServer [as func] (D:\projects\new_proj\node_modules\react-native\node_modules@react-native-community\cli\build\commands\server\runServer.js:82:58)在 Command.handleAction (D:\projects\new_proj\node_modules\react-native\node_modules@react-native-community\cli\build\cliEntry.js:160:21)在 Command.listener (D:\projects\new_proj\node_modules\commander\index.js:315:8)在 Command.emit (events.js:210:5)在 Command.parseArgs (D:\projects\new_proj\node_modules\commander\index.js:651:12)

解决方案

我今天第一次遇到类似的错误.它出现在 \node_modules\metro-config\src\defaults\blacklist.js 中,有一个无效的正则表达式需要更改.我将 sharedBlacklist 下的第一个表达式从:

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

到:

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

  1. I just installed node.js & cli

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

      npm -g react-native-cli
      

  2. And created a 'new project'.

    react-native init new_project
    

  3. and inside that 'new_project' directory, I tired to see if metro bundler works well.

    react-native start
    

  4. But the command gave me following error and metro is not starting. Any clue for fixing this error? (I'm using windows 10 OS.)

    • command : C:\projects\new_proj>react-native start

      error Invalid regular expression: /(.\fixtures.|node_modules[]react[]dist[].|website\node_modules.|heapCapture\bundle.js|.\tests.)$/: Unterminated character class. Run CLI with --verbose flag for more details. SyntaxError: Invalid regular expression: /(.\fixtures.|node_modules[]react[]dist[].|website\node_modules.|heapCapture\bundle.js|.\tests.)$/: Unterminated character class at new RegExp () at blacklist (D:\projects\new_proj\node_modules\metro-config\src\defaults\blacklist.js:34:10) at getBlacklistRE (D:\projects\new_proj\node_modules\react-native\node_modules@react-native-community\cli\build\tools\loadMetroConfig.js:69:59) at getDefaultConfig (D:\projects\new_proj\node_modules\react-native\node_modules@react-native-community\cli\build\tools\loadMetroConfig.js:85:20) at load (D:\projects\new_proj\node_modules\react-native\node_modules@react-native-community\cli\build\tools\loadMetroConfig.js:121:25) at Object.runServer [as func] (D:\projects\new_proj\node_modules\react-native\node_modules@react-native-community\cli\build\commands\server\runServer.js:82:58) at Command.handleAction (D:\projects\new_proj\node_modules\react-native\node_modules@react-native-community\cli\build\cliEntry.js:160:21) at Command.listener (D:\projects\new_proj\node_modules\commander\index.js:315:8) at Command.emit (events.js:210:5) at Command.parseArgs (D:\projects\new_proj\node_modules\commander\index.js:651:12)

解决方案

I just got a similar error for the first time today. It appears in \node_modules\metro-config\src\defaults\blacklist.js, there is an invalid regular expression that needed changed. I changed the first expression under sharedBlacklist 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__\/.*/
];

这篇关于如何解决'react-native start'的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆