"Error: Cannot find module 'metro-core'" when starting an Expo project
Olivia Zamora
Whenever I start Expo Go with the expo start command, this error appears :
Error: Cannot find module 'metro-core'
Require stack:
- /usr/local/lib/node_modules/expo/node_modules/@expo/cli/build/src/start/server/metro/instantiateMetro.js
- /usr/local/lib/node_modules/expo/node_modules/@expo/cli/build/src/start/server/metro/MetroBundlerDevServer.js
- /usr/local/lib/node_modules/expo/node_modules/@expo/cli/build/src/start/server/DevServerManager.js
- /usr/local/lib/node_modules/expo/node_modules/@expo/cli/build/src/start/startAsync.js
- /usr/local/lib/node_modules/expo/node_modules/@expo/cli/build/src/start/index.js
- /usr/local/lib/node_modules/expo/node_modules/@expo/cli/build/bin/cliI have tried to reinstall metro-core, but with no effect.
6 Answers
you are running expo start, try run
npx expo start This should work. Let me know if this works.
3I had uninstalled React Native and installed it again. Then, it worked!
Also, there were some network issues when I scan the QR code using expo go app. The solution was to change the connection from LAN to tunnel using expo start --tunnel command.
Delete the file
package-lock.jsonand the (BIG!) directorynode_modules.Run
npm install. (This may take a while, up to a few minutes.)Finally, run
npm startand see if the error is gone. 1
Note!
The fact that you run
expo startinstead ofnpx expo startindicates that you haven't installed the Expo project locally. The official way to install Expo used to benpm install -g expo-cli. At the time of writing, the official way is instead a local installation :npx create-expo-app Your-project-name.
Then change directory to your project,cd Your-project-name.
(Runningnpm installat this point is a good idea.)
Finally, runnpm startto start your Expo project.
Do not install theexpopackage globally. 2Here is a screenshot of the error
Cannot find module 'metro-core' …
- The
react-nativepackage depends directly onmetro-runtime. My best guess is that there is some intricate bug in one or both of those packages – or in some package that they depend on. Very hard to tell. Very hard to reproduce, as this happens intermittently.
1Whether you run npm start – or npx expo start – or npm run start should not make any difference at all.
2To uninstall, run npm -g uninstall expo-cli (or yarn global remove expo-cli).
I am on Linux machine. expo start gives the same error. Instead
npm run start works without issue
I kind of encountered this problem right now, and the reason it occured was running npm audit fix --forceWhich was leaving a danger message of vulnerability. I had to reinstall react-native to
Install the metro packages globally with:npm i -g metro metro-core