7

I am trying to run react-native start and the following error appears

"Cannot find module 'metro-core'.  Run CLI with --verbose flag for more details. 

Prior to getting this message, I had a different error message saying modules was not located, so I tried this:

Delete the node_modules folder -

rm -rf node_modules && npm install
Reset packager cache - rm -fr $TMPDIR/react-* or node_modules/react-native/packager/packager.sh --reset-cache
Clear watchman watches - watchman watch-del-all

I just typed in the react-native start and the error message popped up on the simulator, which told me to look at my terminal for the error message.

2 Answers 2

10

This is common with NPM. Do not worry. Just follow a few steps and you will get your package.

Step 1: $ npm cache clean --force

Step 2: delete node_modules by $ rm -rf node_modules folder or delete it manually by going into the directory and right-click > delete.

Step 3: npm install

To start again, $ npm start

This worked for me. Hopes it works for you too.

Still, if it is there, kindly checks the error it displays in red and acts accordingly. Be careful when using rm -rf.

After that,

While working on Unix systems.

  • Sometimes it may not allow you to install such packages. For that, you need sudo permissions.

  • Sometimes, the package is installed but only in your local modules, and when you try to import(require) it from outside of the directory, the error occurs.

  • Sometimes, your compiler read your dependencies, but not able to find this package in that, at that time also you face this error.

Anyways, don't worry. You just have to follow some steps below.

  1. A best practice is to initialize your project using npm init before starting development. This will initialize your project and generate package.json file. (Ignore it if your project have package.json file)
  2. Then, if you want any library as dependencies, try --save with npm install command. This will save your dependency in package.json file. e.g. npm install metro-core --save

  3. If any package is not found after installing, install it globally by -g flag. Globally installed packages will be accessible within your system. e.g. npm install metro-core -g.

Note: Unix system needs SUDO permission for installing it globally.

I hope this will help you.

Sign up to request clarification or add additional context in comments.

Comments

1
npm install metro-core 

use command then run

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.