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 (<anonymous>)
    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__\/.*/
];
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章