【问题标题】:I am getting Invalid regular expression error while running npm start运行 npm start 时出现 Invalid regular expression 错误
【发布时间】:2020-02-04 17:08:14
【问题描述】:

我最近安装了 expo。我已经使用 expo init 创建了一个项目。 创建后,当我运行 npm start 时出现以下错误,请解决我的问题

> @ start C:\Users\ujwal\Desktop\Java\my-new-project
> expo start

Starting project at C:\Users\ujwal\Desktop\Java\my-new-project
Expo DevTools is running at http://localhost:19002
Opening DevTools in the browser... (press shift-d to disable)
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.

Metro Bundler process exited with code 1
Set EXPO_DEBUG=true in your env to view the stack trace.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ start: `expo start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @ start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\ujwal\AppData\Roaming\npm-cache\_logs\2019-10-07T11_19_27_567Z-debug.log

【问题讨论】:

  • 请分享你的节点,expo版本。
  • “expo”:“^35.0.0”,“expo-cli”:“^2.10.1”,“package”:“^1.0.1”,“react”:“16.8. 3", "react-dom": "16.8.3",

标签: react-native npm expo


【解决方案1】:

您必须在此文件中进行更改{project_root}\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__\/.*/
];

希望对你有所帮助....

【讨论】:

  • 是的,它确实有效,但你能解释一下是什么导致了这个错误吗?我刚刚将我的项目从一个目录移动到另一个目录。它在我以前的目录中运行良好,但是在将它移动到新目录后我必须这样做。
  • @KashanHaider 它卡在加载图上
【解决方案2】:

您似乎遇到了这个错误:https://github.com/facebook/react-native/issues/26598。根据问题单,您有一些选择:

第一个选项:降级到节点 10.16.3 LTS

第二个选项:如果您使用 Yarn,请在您的 package.json 中添加一个 'resolutions' 属性,以指向解决问题的 metro-config 版本:

  "resolutions": {
    "metro-config": "0.57.0"
  },

第三个选项:如果你使用 npm 而不是 yarn,你需要想办法将“metro-config”子依赖修复为“0.57.0”。我不知道该怎么做,也许 npm-shrinkwrap 可以帮助你。

【讨论】:

    【解决方案3】:

    在 Windows 上使用 react(而不是 react-native),遇到了同样的问题。使用更新版本的节点修复它。

    【讨论】:

    • 这并没有提供问题的答案。要批评或要求作者澄清,请在他们的帖子下方留下评论。 - From Review
    • @SuleymanSah 这个答案既不批评也不要求作者澄清。
    【解决方案4】:

    在安装新的 expo-template-tabs 项目然后运行 ​​expo start 后,我今天遇到了同样的问题。

    您需要在文件中进行更改:

    {project_root}\node_modules\metro-config\src\defaults\blacklist.js
    

    有一个无效的正则表达式需要更改。所以请改变这个:

    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__\/.*/
    ];
    

    this answer 所见,由 Kishan Gujarati 提供。

    【讨论】:

    • 欢迎来到 StackOverflow!您的回答应该是评论,因为它指的是对另一个问题的回答。
    • 我试图向 Kishans Post 添加评论,但它不允许我这样做。它说“你必须有 50 声望才能发表评论”
    • 没问题。我建议对您的答案进行编辑。如果您指的是另一个问题的答案,请尽量保持这种状态。
    猜你喜欢
    • 1970-01-01
    • 2020-07-02
    • 2021-01-01
    • 2021-12-18
    • 1970-01-01
    • 2021-09-07
    • 2021-02-02
    • 1970-01-01
    • 2022-11-19
    相关资源
    最近更新 更多