This article is about fixing react-native/cli not found error caused by `use_native_modules!` in React Native Community CLI
  • 07-Feb-2023
Lightrun Team
Author Lightrun Team
Share
This article is about fixing react-native/cli not found error caused by `use_native_modules!` in React Native Community CLI

react-native/cli not found error caused by `use_native_modules!` in React Native Community CLI

Lightrun Team
Lightrun Team
07-Feb-2023

Explanation of the problem

After upgrading a brownfield iOS project from version 0.59.9 to 0.62.0, an error is encountered while executing the pod install command:

[!] Invalid `Podfile` file: [!] /Users/dude/.nvm/versions/node/v12.16.1/bin/node -e try {console.log(require('@react-native-community/cli').bin);} catch (e) {consol
e.log(require('react-native/cli').bin);}

internal/modules/cjs/loader.js:985
  throw err;
  ^

Error: Cannot find module 'react-native/cli'
Require stack:
- /myapp/ios/[eval]
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:982:15)
    at Function.Module._load (internal/modules/cjs/loader.js:864:27)
    at Module.require (internal/modules/cjs/loader.js:1044:19)
    at require (internal/modules/cjs/helpers.js:77:18)
    at [eval]:1:87
    at Script.runInThisContext (vm.js:120:20)
    at Object.runInThisContext (vm.js:311:38)
    at Object.<anonymous> ([eval]-wrapper:10:26)
    at Module._compile (internal/modules/cjs/loader.js:1158:30)
    at evalScript (internal/process/execution.js:94:25) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/myapp/ios/[eval]' ]
}

The error is caused by the following line in the Podfile:

use_native_modules!

A similar error is encountered in an Android project when executing the gradle sync command:

Gradle sync failed: Cause: internal/modules/cjs/loader.js:985  throw err;  
^Error: Cannot find module 'react-native/cli'Require stack:- /myapp/android/[eval]    
  at Function.Module._resolveFilename (internal/modules/cjs/loader.js:982:15)    
  at Function.Module._load (internal/modules/cjs/loader.js:864:27)    
  at Module.require (internal/modules/cjs/loader.js:1044:19)    
  at require (internal/modules/cjs/helpers.js:77:18)    
  at [eval]:1:13    
  at Script.runInThisContext (vm.js:120:20)    
  at Object.runInThisContext (vm.js:311:38)    
  at Object.<anonymous> ([eval]-wrapper:10:26)    
  at Module._compile (internal/modules/cjs/loader.js:1158:30)    
  at evalScript (internal/process/execution.js:94:25) {  code: 'MODULE_NOT_FOUND',  requireStack: [    '/myapp/android/[eval]'  ]}
				Consult IDE log for more details (Help

Troubleshooting with the Lightrun Developer Observability Platform

Getting a sense of what’s actually happening inside a live application is a frustrating experience, one that relies mostly on querying and observing whatever logs were written during development.
Lightrun is a Developer Observability Platform, allowing developers to add telemetry to live applications in real-time, on-demand, and right from the IDE.

  • Instantly add logs to, set metrics in, and take snapshots of live applications
  • Insights delivered straight to your IDE or CLI
  • Works where you do: dev, QA, staging, CI/CD, and production

Start for free today

Problem solution for react-native/cli not found error caused by `use_native_modules!` in React Native Community CLI

The error “react-native/cli not found” caused by the use_native_modules! in React Native Community CLI is likely due to an outdated version of React Native Community CLI. You can resolve this issue by updating the React Native Community CLI to the latest version.

Here are the steps to update React Native Community CLI:

  1. Uninstall the current version of React Native Community CLI by running the following command:
npm uninstall -g react-native-cli
  1. Install the latest version of React Native Community CLI by running the following command:
npm install -g @react-native-community/cli
  1. Once the installation is complete, try running your React Native project again.

This should resolve the “react-native/cli not found” error and allow you to use use_native_modules! in your project without any issues.

Other popular problems with React Native Community CLI

Problem: React Native Community CLI not found error

This error occurs when the user tries to run a react-native project using the command “react-native run-ios” or “react-native run-android”. The error message displayed is “Command ‘react-native’ not found”.

Solution:

The issue occurs when the React Native Community CLI is not installed on the system. To resolve the issue, install the React Native Community CLI globally by running the command “npm install -g react-native-cli”. After the installation, try running the project again.

Problem: Unable to resolve module error

This error occurs when the user tries to build and run the React Native project. The error message displayed is “Unable to resolve module <module_name> from <file_path>”.

Solution:

The issue occurs when the imported module is not installed in the project. To resolve the issue, install the missing module by running the command “npm install <module_name>”. After the installation, try building and running the project again.

Problem: Metro bundler not running error

This error occurs when the user tries to run the React Native project. The error message displayed is “Metro Bundler is not running. To run your app on iOS, you need to launch the Metro Bundler by running ‘react-native run-ios’ or ‘npx react-native run-ios'”.

Solution:

The issue occurs when the Metro bundler, which is a development server for React Native, is not running. To resolve the issue, run the command “react-native start” or “npx react-native start” to start the Metro bundler. After the Metro bundler is running, try running the project again.

A brief introduction to React Native Community CLI

React Native Community CLI is a command-line interface tool that allows developers to create and manage React Native projects. It provides a set of commands that enable developers to create, run and test their React Native applications. The tool supports a wide range of functionalities, from initial project setup to building and publishing the app.

React Native Community CLI is an open-source tool that integrates with other tools such as Xcode, Android Studio, and Visual Studio Code to provide an end-to-end development experience. The CLI tool provides a streamlined way to manage the entire React Native project lifecycle and helps developers to avoid common pitfalls and challenges. The tool supports various features such as hot-reloading, debugging, and unit testing, making the development process faster and more efficient.

Most popular use cases for React Native Community CLI

  1. Setting up a React Native Project: The React Native Community CLI provides an easy way to set up a React Native project. This process involves creating a new project, setting up an environment for development, and installing necessary dependencies. The CLI can be invoked with a simple command line command, npx react-native init <ProjectName>, where <ProjectName> is the name of the new project being created.
npx react-native init MyApp
  1. Running the React Native App on a Simulator or Physical Device: The CLI allows developers to run the React Native app on either a simulator or physical device. This is done by using the command line command, npx react-native run-ios or npx react-native run-android. The CLI will take care of setting up the environment, installing the necessary dependencies, and launching the app.
npx react-native run-ios
  1. Debugging and Troubleshooting React Native Apps: The React Native Community CLI provides various debugging tools and utilities to help developers troubleshoot their apps. This includes options such as debugging the JavaScript code, viewing the logs, and profiling the performance of the app. The CLI can also be used to inspect the hierarchy of views in the app, and to interact with the React Native components from the developer console.
Share

It’s Really not that Complicated.

You can actually understand what’s going on inside your live applications.

Try Lightrun’s Playground

Lets Talk!

Looking for more information about Lightrun and debugging?
We’d love to hear from you!
Drop us a line and we’ll get back to you shortly.

By submitting this form, I agree to Lightrun’s Privacy Policy and Terms of Use.