1
resposta

Unable to load script, metro server ou index.android.bundle

Ao tentar executar o aplicativo instalura através do comando "npx react-native run-android" ocorre erro no emulador no Android Studio.

O erro é :

Unable to load script. Make sure you-re either runnig a Metro server (run 'react-native start') or that your bundle 'index.android.bundle' is packaged corretly for release.

Aí ao executar o run "react-native start" ocorre o erro:

rror 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 (C:\Users\vinic\Google Drive.net\Alura\Reactnative\Instalura\node_modules\metro-config\src\defaults\blacklist.js:34:10) at getBlacklistRE (C:\Users\vinic\Google Drive.net\Alura\Reactnative\Instalura\node_modules\react-native\node_modules@react-native-community\cli\build\tools\loadMetroConfig.js:69:59) at getDefaultConfig (C:\Users\vinic\Google Drive.net\Alura\Reactnative\Instalura\node_modules\react-native\node_modules@react-native-community\cli\build\tools\loadMetroConfig.js:84:20) at load (C:\Users\vinic\Google Drive.net\Alura\Reactnative\Instalura\node_modules\react-native\node_modules@react-native-community\cli\build\tools\loadMetroConfig.js:112:25) at Object.runServer [as func] (C:\Users\vinic\Google Drive.net\Alura\Reactnative\Instalura\node_modules\react-native\node_modules@react-native-community\cli\build\commands\server\runServer.js:82:58) at Command.handleAction (C:\Users\vinic\Google Drive.net\Alura\Reactnative\Instalura\node_modules\react-native\node_modules@react-native-community\cli\build\cliEntry.js:160:21) at Command.listener (C:\Users\vinic\Google Drive.net\Alura\Reactnative\Instalura\node_modules\commander\index.js:315:8) at Command.emit (events.js:314:20) at Command.parseArgs (C:\Users\vinic\Google Drive.net\Alura\Reactnative\Instalura\node_modules\commander\index.js:651:12)

1 resposta

Olá Vinicius,

Qual versão do node você está utilizando? Dando uma olhada na internet alguns usuários utilizando a versão >12.11 tiveram esse mesmo problema e fazendo downgrade para 12.10 e recriando o projeto conseguiram resolver

Um outra solução é ir em: node_modules/metro-config/src/defaults/blacklist.js e alterar:

De

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

Para

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

Pode testar?

Abraços e Bons Estudos!