Reading timeยท3 min
To solve the error "react-native is not recognized as an internal or external command, operable program or batch file":
react-native
command with npx
instead of using it directly.react-native-cli
package globally.'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.
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.
npm install -g npm@latest --force
If you get an error that npx
is not installed, install it by running the
following command.
# ๐๏ธ for Windows npm install -g npx # ๐๏ธ for macOS or Linux sudo npm install -g npx
npx
, run CMD as an administrator and rerun the command.To open CMD as an administrator:
Click on the Search bar and type CMD.
Right-click on the Command Prompt application and click "Run as administrator".
You can also use the npx react-native
command in an existing project.
yarn react-native start npx react-native start
Alternatively, you can add a start
script in your package.json
file.
{ "scripts": { "start": "react-native start" } }
Then you can run the script with the npm run start
command.
npm run start
Alternatively, you can install the react-native-cli package globally.
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.
npm
to your PATH environment variableTo add npm
to your PATH environment variable:
npm
directory is most likely located under
%USERPROFILE%\AppData\Roaming\npm
or in other words,
C:\Users\YOUR_USER\AppData\Roaming\npm
.%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.
npm config get prefix
Add the path to npm
and click on "OK" twice to confirm.
Close your Command prompt application and then reopen it.
You might also have to restart your PC, but that's not always necessary.
react-native
command after you've restarted your shell.You can learn more about the related topics by checking out the following tutorials: