blogging

Metro Bundler error: Invalid regular expression | node > 12.9 Windows

TLDR: If you’re doing React Native Expo development on a Windoze machine and have node version > 12.9 Metro Bundler will fail with a regex error:

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

Seems like two fixes for this:

  1. Downgrade your version of node, as stated on this expo-cli GitHub ticket
  2. Update the regex in 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__\/.*/
    ];
    note the additional escapes in the expr: /node_modules[\/\\]react[\/\\]dist[\/\\].*/,
    the difference is very subtle

Hoping this helps anyone encountering this issue. If you don’t downgrade node (which might not be an option for everyone), then every new project or any time you npm i, you’ll need to perform this regex replacement in the metro-config/src/defaults/blacklist.js file.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.