Atom Lab logo

Getting a React Native command not found error? Here's how to fix it.

Request, Deliver, Revise, Done

Get unlimited UI Design & React Development for a fixed monthly price

50% off your first month

Introduction

If you find yourself getting a “command not found” error when you try to initialise a React Native project (or run any other React Native CLI command), you are likely using an outdated method of running the React Native CLI. In this article I will explain the problem and tell you how to fix it so you can get up and running again.

React native not found error

Why am I seeing “command not found: react-native”?

If you are getting this error, it means that either you do not have the CLI installed on your machine, or you do not have it configured properly.

In the past I would have spent the rest of this article telling you how to install the CLI the old fashion way by running npm install -g react-native-cli, and ensuring it’s in your machines path.

Thankfully, npm now provides a much simpler option than going through all that hassle. Instead, we can use NPX to run the latest CLI version on demand without having to configure anything.

What is NPX?

NPX is a tool included in NPM (from version 5.2) that allows you to run executables that you would normally install via NPM directly. The major advantage of using npx is that it requires no configuration, and it will always run the latest version of the package that you’re executing.

This makes it ideal for something like the React Native CLI, which would traditionally have been installed globally and become out of date relatively quickly unless you remember to update it.

How to check that you have NPX available

To check that you have npx available, simply run the following command in your terminal:

which npx
Checking that we have access to npx

This should return the directory path to your npx install - if so, you’re ready to go! If not, then you can install npx by running:

npm install -g npx

How to use the npx version of React Native CLI

Now that you’ve confirmed that you have access to npx, you should now be able to initialise a React Native project by running the following command in your terminal:

npx react-native init MyProject

It will ask you for permission to install the react-native package - simply enter y to proceed and your React Native project should be bootstrapped!

You can run any command via the npx version that you would on the npm version - for example to start the metro bundler, simply run the following in your project root:

npx react-native start

Copyright 2024 - Atom Lab | Privacy Policy | Terms and Conditions