'react-native' is not recognized as an internal or external command

avatar
Borislav Hadzhiev

3 min

banner

# 'react-native' is not recognized as an internal or external command

To solve the error "react-native is not recognized as an internal or external command, operable program or batch file":

  1. Prefix the react-native command with npx instead of using it directly.
  2. Alternatively, install the react-native-cli package globally.

react native is not recognized as internal or external command

shell
'react-native' is not recognized as an internal or external command, operable program or batch file The term 'react-native' is not recognized as the name of a cmdlet, function, script file, or operable program.

The first thing you should try is to prefix the react-native command with npx as shown in this GitHub repo.

cmd
npx react-native init MyApp cd MyApp npx react-native start

If you get an error stating that "cb.apply is not a function", you have to update your npm version.

cmd
npm install -g npm@latest --force

If you get an error that npx is not installed, install it by running the following command.

cmd
# ๐Ÿ‘‡๏ธ for Windows npm install -g npx # ๐Ÿ‘‡๏ธ for macOS or Linux sudo npm install -g npx

install npx

If you get a permissions error when trying to install npx, run CMD as an administrator and rerun the command.

To open CMD as an administrator:

  1. Click on the Search bar and type CMD.

  2. Right-click on the Command Prompt application and click "Run as administrator".

run cmd as administrator

You can also use the npx react-native command in an existing project.

cmd
yarn react-native start npx react-native start

Alternatively, you can add a start script in your package.json file.

package.json
{ "scripts": { "start": "react-native start" } }

Then you can run the script with the npm run start command.

cmd
npm run start

Alternatively, you can install the react-native-cli package globally.

shell
npm uninstall -g react-native-cli npm install -g react-native-cli react-native init AwesomeApp

If you get a permissions error, prefix the commands with sudo or open CMD as an administrator.

If none of the suggestions helped, try restarting your terminal and your IDE.

Alternatively, you can follow the "setting up the development environment" instructions in this section of the React Native docs.

If the error persists, add npm to your PATH environment variable manually.

# Add npm to your PATH environment variable

To add npm to your PATH environment variable:

  1. Click on the Search bar and type "environment variables".
  2. Click on "Edit the system environment variables".

edit system environment variables

  1. Click on the "Environment Variables" button.

click environment variables

  1. In the "System variables" section, select the "Path" variable and click "Edit".

select path and click edit

  1. Click on "New" and then click "Browse".

click new browse

  1. Your npm directory is most likely located under %USERPROFILE%\AppData\Roaming\npm or in other words, C:\Users\YOUR_USER\AppData\Roaming\npm.
location
%USERPROFILE%\AppData\Roaming\npm # ๐Ÿ‘‡๏ธ same as below (make sure to replace YOUR_USER) C:\Users\YOUR_USER\AppData\Roaming\npm

If you can't find it, run the npm config get prefix command.

cmd
npm config get prefix

npm config get prefix

  1. Add the path to npm and click on "OK" twice to confirm.

  2. Close your Command prompt application and then reopen it.

Note that you must restart your Command prompt shell for the changes to take effect.

You might also have to restart your PC, but that's not always necessary.

  1. Try to issue a react-native command after you've restarted your shell.

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.

Copyright ยฉ 2023 Borislav Hadzhiev