You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Expo-CLI启动React Native项目时遇正则表达式错误求助

Fix for "Unterminated character class" Error When Starting Expo Project

Hey there! That regex error you're hitting is super common when using older Expo/Metro versions with Node.js 12 or newer—let's work through how to fix this.

What's causing this?

Node.js 12 tightened up its regex syntax checks, and the older version of Metro Bundler (the tool Expo uses to bundle your app) has a malformed regex in its blacklist config. The problematic bit is node_modules[\\\]react[\\\]dist[\\\].*—those triple backslashes break the regex structure, triggering the "unterminated character class" error.

Solutions to try:

1. Upgrade your Expo project (Recommended)

This is the best long-term fix, as it brings your project up to date with dependencies that play nice with newer Node versions:

  • Open your terminal, navigate to your project folder:
    cd D:\Final Year Project\practice\rn-test-app
    
  • Run the Expo upgrade command:
    expo upgrade
    
  • Follow the prompts to update your project to the latest compatible Expo SDK version. Once done, fire up npm start again.

2. Manually patch the Metro config (Temporary quick fix)

If you can't upgrade right now, you can fix the problematic regex directly (note: this change will get overwritten if you reinstall node_modules later):

  • Head to node_modules/metro-config/src/defaults/blacklist.js in your project
  • Find the line with the regex that includes node_modules[\\\]react[\\\]dist[\\\].*
  • Replace the triple backslashes (\\\) with double backslashes (\\) so that section becomes:
    node_modules[\\/]react[\\/]dist[\\/].*
    
  • Save the file, then restart your Expo dev server with npm start

3. Downgrade Node.js to version 10.x

If neither of the above works, you can use a Node version manager (like nvm for Windows/macOS/Linux) to switch to Node 10, which doesn't have this strict regex validation:

  • Install nvm if you haven't already
  • Run these commands:
    nvm install 10
    nvm use 10
    
  • Restart your terminal, then run npm start again

Your error log for reference:

EXPO CLI ERROR
PS D:\Final Year Project\practice\rn-test-app> npm start
@ start D:\Final Year Project\practice\rn-test-app

expo start
Starting project at D:\Final Year Project\practice\rn-test-app
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
Error: Metro Bundler process exited with code 1
at ChildProcess. (C:@expo\xdl@56.2.8\src\Project.ts:1804:16)
at Object.onceWrapper (events.js:300:26)
at ChildProcess.emit (events.js:210:5)
at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)
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\ANONYMOUS\AppData\Roaming\npm-cache_logs\2019-10-08T21_04_22_912Z-debug.log

内容的提问来源于stack exchange,提问作者Abdullah

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 08:12:01