"Error: Cannot find module 'metro-core'" when starting an Expo project
Asked Answered
R

8

13

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/cli

I have tried to reinstall metro-core, but with no effect.

Rickettsia answered 27/8, 2022 at 9:32 Comment(0)
T
23

you are running expo start, try run

npx expo start 

This should work. Let me know if this works.

Tameika answered 30/8, 2022 at 2:10 Comment(3)
Yes, it works. But I had other troubles because the connection was LAN, so it didn't work when I tried it. Thanks so much.Rickettsia
I saw this issue because I just didn't include the "start": npx expo@latest --dev-client It'll appear to like this command and do something, but it should say something to the effect of 'invalid command'.Huebner
i have the same issue and im using npx expo startXylotomous
R
5

I 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.

Rickettsia answered 29/8, 2022 at 20:34 Comment(1)
Surprisingly, this worked for me as well.Connor
F
2
  1. Delete the file package-lock.json and the (BIG!) directory node_modules.

  2. Run npm install. (This may take a while, up to a few minutes.)

  3. Finally, run npm start and see if the error is gone. 1

Note!

  1. The fact that you run expo start instead of npx expo start indicates that you haven't installed the Expo project locally. The official way to install Expo used to be npm 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.
    (Running npm install at this point is a good idea.)
    Finally, run npm start to start your Expo project.
    Do not install the expo package globally. 2

  2. Here is a screenshot of the error Cannot find module 'metro-core' …

Error:  Cannot find module 'metro-core'

  1. The react-native package depends directly on metro-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.

1 Whether you run npm start – or npx expo start – or npm run start should not make any difference at all.

2 To uninstall, run npm -g uninstall expo-cli (or yarn global remove expo-cli).

Faint answered 2/10, 2023 at 14:55 Comment(0)
D
1

I am on Linux machine. expo start gives the same error. Instead

 npm run start 

works without issue

Deina answered 24/3, 2023 at 16:38 Comment(0)
B
0

I kind of encountered this problem right now, and the reason it occured was running npm audit fix --force Which was leaving a danger message of vulnerability. I had to reinstall react-native to

Bowne answered 19/3, 2023 at 9:1 Comment(0)
L
0

Install the metro packages globally with: npm i -g metro metro-core

Laos answered 2/8, 2023 at 13:56 Comment(0)
W
0

I came to this post because I have been using pnpm to install the packages and pnpm dlx to execute, the problem is resolved once I gave up and used npm instead.

Wallywalnut answered 28/12, 2023 at 2:45 Comment(0)
G
0

The following solution helped me:

  1. Delete the file package-lock.json and the (BIG!) directory node_modules.

  2. Run npm install. (This may take a while, up to a few minutes.

Gerladina answered 24/7 at 15:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.