npm启动时出现Invalid regular expression无效的正则表达式错误

项目在迁移过程中可能会出现无效的正则表达式错误

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 (E:\SDL\RN\lgisrn\node_modules\metro-config\src\defaults\blacklist.js:34:10)
    at getBlacklistRE (E:\SDL\RN\lgisrn\node_modules\react-native\node_modules\@react-native-community\cli\build\tools\loadMetroConfig.js:66:59)
    at getDefaultConfig (E:\SDL\RN\lgisrn\node_modules\react-native\node_modules\@react-native-community\cli\build\tools\loadMetroConfig.js:82:20)
    at load (E:\SDL\RN\lgisrn\node_modules\react-native\node_modules\@react-native-community\cli\build\tools\loadMetroConfig.js:118:25)
    at Object.runServer [as func] (E:\SDL\RN\lgisrn\node_modules\react-native\node_modules\@react-native-community\cli\build\commands\server\runServer.js:82:58)
    at Command.handleAction (E:\SDL\RN\lgisrn\node_modules\react-native\node_modules\@react-native-community\cli\build\index.js:164:23)
    at Command.listener (E:\SDL\RN\lgisrn\node_modules\commander\index.js:315:8)
    at Command.emit (events.js:223:5)
    at Command.parseArgs (E:\SDL\RN\lgisrn\node_modules\commander\index.js:651:12)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `react-native start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] 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\Administrator\AppData\Roaming\npm-cache\_logs\2020-02-11T02_59_41_448Z-debug.log

有人降低node版本后解决,但并不是总有效
也可修改报错代码解决:
文件{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__\/.*/
];

你可能感兴趣的:(npm启动时出现Invalid regular expression无效的正则表达式错误)