metro-config sharedBlacklist regexp without scape "\"

Created on 27 Sep 2019  路  39Comments  路  Source: facebook/metro

Do you want to request a feature or report a bug?
bug

What is the current behavior?
When i try to run react-native start an error is outputed

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 (<anonymous>)
    at blacklist (C:\Users\***\react\myApp\node_modules\metro-config\src\defaults\blacklist.js:34:10)
    at getBlacklistRE (C:\Users\***\react\myApp\node_modules\@react-native-community\cli\build\tools\loadMetroConfig.js:69:59)
    at getDefaultConfig (C:\Users\***\react\myApp\node_modules\@react-native-community\cli\build\tools\loadMetroConfig.js:85:20)
    at load (C:\Users\***\react\myApp\node_modules\@react-native-community\cli\build\tools\loadMetroConfig.js:121:25)
    at Object.runServer [as func] (C:\Users\***\react\myApp\node_modules\@react-native-community\cli\build\commands\server\runServer.js:82:58)
    at Command.handleAction (C:\Users\***\react\myApp\node_modules\@react-native-community\cli\build\cliEntry.js:160:21)
    at Command.listener (C:\Users\***\react\myApp\node_modules\commander\index.js:315:8)
    at Command.emit (events.js:210:5)
    at Command.parseArgs (C:\Users\***\react\myApp\node_modules\commander\index.js:651:12)

Please provide your exact Metro configuration and mention your Metro, node, yarn/npm - =-- - version and operating system.

Most helpful comment

Replace existing shareBlacklist with this:

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

All 39 comments

This bug is caused due to Node's parsing of regular expressions in Node versions >=12.11.0.

These regular expressions should be fixed without any compatibility issues with older Node versions...

12.11.0 did not work for me, only 12.10.0 (Did not test below that but probably works) managed to fix the error, weirdly.

Thank you @RohitChattopadhyay, your changes worked on my windows 10.

This problem occurred when I run expo start for react-native application.

I was having the same problem. I was using node version 12.11.1 . I've changed to the LTS version of node and now everything is working fine.

Try
npm install metro-core

Try
npm install metro-core

not work for me

As mentioned on stackoverflow.
Escaping '/' of sharedBlacklist
in \node_modules\metro-config\src\defaults\blacklist.js works for me on node v12.13.0

@xunzhou That's worked very well for me in Windows 10. Thanks.

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

Same problem with me, fixed it from here :
https://stackoverflow.com/a/58122821

I wish this problem was fixed, I'm having it in every install.

I wish this problem was fixed, I'm having it in every install.

Same here.

Replace existing shareBlacklist with this:

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

Same problem with me, fixed it from here :
https://stackoverflow.com/a/58122821

Worked this way
Is it possible to turn it into globals?
Or should each new project be modified?

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"
  },
 ...

why is this still an issue?!

Can report that i can reproduce it on a Win10 with a fresh installed react-native

I can report that even on 0.57.0 with the supposed fix https://github.com/facebook/metro/commit/7c6f30b592b2fb23cee55b54f1aa4b7a522dec18 this is still a problem

This is caused by node v12.11.0.

To fix it go to:

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

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

Not clear why this issue was closed.
Is this fixed in latest RN pre-release ?

I am using latest version of node Long Term supported release (LTS)
v12.14.1
Running up to date Windows 10.
using react-native 0.60

The problem is there, and I do not think manual modification inside of node_modules is a solution.
This works for developer machines but not for automated build processes that are meant to use package-lock.json and install a 'reproducible build' env.

Node v12.11 was released September 25th 2019. Now it is Jan 12, 2020.
So folks cannot do release builds for about 3 months.

Still problem. Not fixed

Recently I've upgraded node to 12.14.1 and this problem happend with my Expo app.
First I've deleted node_modules and *.lock files, then I've installed newest version of expo-cli, then run yarn to install all my packages and it's working

Same problem.
This solve it: https://github.com/facebook/metro/issues/453#issuecomment-568769943

NodeJs: v12.4.1
react-native v0.61.5

NOTE: Metro config allows to pass blocklist (previouslly blacklistRE) param (https://facebook.github.io/metro/docs/configuration/#blocklist).
I don't think modifying the library manually is necessary.
I haven't try this yet. I'll comment on this when I do.

Can confirm that this is till an issue...

Try
npm install metro-core

It worked man!

Same problem here. Node v12.16.2

metro-config folder under node_modules is missing. Then what is next solution ?

for me it get resolved by downgrading the nodeJs version i tried with 8.17.0 and its working

The real fix is in #578.

Today is 21 September 2020, still need every react native user fix the string error by self (already after npm update)

Today is 21 September 2020, still need every react native user fix the string error by self (already after npm update)

node_modules\metro-config\src\defaults
but now I found those codes from October 26 1985, seem should not angry :)

how is this still an issue? I dont understand? @devs why is this issue closed? theres multimple MR's that have been submitted it looks like to resolve this ... what is the reasoning behind not fixing this?

Wait, is it still up? Haven't it been fixed in the latest versions already?

Im not entirely sure ... all i know is i installed react-vr and it errored out with this message about bad regex and spent way longer than i wanted to trying to figure out what was wrong ... maybe react-vr is bundling an older version i guess in which case ill go nag them

It seems they fix it in the latest release v0.64.0

[Breaking]: Renames the Metro transform.inlineRequires.blacklist option to blockList. (b25fe89)
[Fix]: Correctly escape the path separator in blocklist regular expressions on Windows (881d9f6)

My blacklist.js file has been completely deleted... is there any way to find the entire file not just the regular expression that needs to be changed?

error Cannot find module 'metro-config/src/defaults/blacklist'

For the folks still having issue. The blacklist.js has been renamed to exclusionList. So go to metro.config.js and replace the import from :
const blacklist = require('metro-config/src/defaults/blacklist');
to:
const blacklist = require('metro-config/src/defaults/exclusionList');

Was this page helpful?
0 / 5 - 0 ratings