ChatGPT解决这个技术问题 Extra ChatGPT

React Native Error - yarn' is not recognized as an internal or external command

I am not able to run the sample react Native AwesomeProject project.

Can anyone help? Below is the details.

C:\Users\dip\AwesomeProject>react-native run-android 'yarn' is not recognized as an internal or external command, operable program or batch file. Scanning 557 folders for symlinks in C:\Users\dip\AwesomeProject\node_mo ules (31ms) JS server already running. Building and installing the app on the device (cd android && gradlew.bat instal Debug)... Error occurred during initialization of VM java/lang/NoClassDefFoundError: java/lang/Object Could not install the app on the device, read the error above for details. Make sure you have an Android emulator running or a device connected and have set up your Android development environment: https://facebook.github.io/react-native/docs/android-setup.html

Note: If you don't have administrator privileges on your system, npm install -g yarn will not add yarn to your executable path, which will produce this error.

k
kvantour

I faced the same issue and it got resolved by below command

npm install -g yarn

this resolved my issue after installing yarn via choco (failed to run on yarn install)
After running this command it was not working for me, then I go to C:\Users\\AppData\Roaming\npm and deleted yarn.ps1 then it works!
C
Community

Yarn is a tool created by facebook as an efficient alternative for npm. In your case.. it is just informing that Yarn is not installed in your system. It is not the culprit.

The problem lies in Error occurred during initialization of VM java/lang/NoClassDefFoundError: java/lang/Object Could not install the app on the device line. It looks like an error with the Java installation.

Solution: Go to C:\Windows\System32 directory and delete java.exe (or rename it to something like java.exe.old)

refer this answer for more details https://stackoverflow.com/a/30577609/5597641.

btw you can install Yarn by typing npm install -g yarn in your command prompt.


G
General Grievance

you have to install yarn globally in your windows OS type this in CMD

npm install -g yarn

you can check yarn version by typing yarn --version on CMD


O
Orlyyn

You should probably insert your Yarn folder in your Environment Variables.

If you already performed the command

npm install -g yarn

and still can't use yarn via terminal, check the following folder: C:\Users\[your user]\AppData\Roaming\npm

If there`s a yarn file there, just put that directory in your Path variable.


A
Apurv Jha

Step 1: Run the below command

npm install -g yarn

Step 2: Check that Yarn is installed by running:

yarn --version

Step 3: If the above version command is not running then go to your C:\Users\<username>\AppData\Roaming\npmand delete yarn.ps1 if it is there.

Done!!!


j
jgritten

Go here https://yarnpkg.com/en/docs/install

Install

Restart any terminals you had open.

yarn -v

...for confirmation

You should be good to go


E
Eren Vardar

Computer > Properties > Advanced System Setting > Environment Variables > Path edit add ; code

C:\Program Files (x86)\Yarn\bin\; OR C:\Users\Username\AppData\Local\Yarn\bin\;


for Windows after changing system environments you need to close and reopen the terminal
P
Prakash Reddy

install node here and then run npm install -g yarn command in terminal


R
Rajnikant Lodhi

If you are facing this error yarn: The term 'yarn' is not recognized as the name of a cmdlet, function, script file, or operable program. then Just run this command

npm install -g yarn

and Check yarn version in your systems

yarn -v

After this installation, you are showing above error then go to this page

https://classic.yarnpkg.com/en/docs/install/#windows-stable 

yarn install by manual


P
Patrick de Ruijter

Try npx yarn start. This worked for me.


A
Alijon Jumanazarov

if you typed npm install -g yarn and getting still the same error then update your node and npm to latest stable version, whenever you install node to latest version npm also updated so one way to solve this problem is installing node from its official website


m
mustafa

you need to set your environment variable -go to your yarn folder then bin -copy that path -save it in your environment variable as yarn


j
juanitourquiza

I use this option to install https://classic.yarnpkg.com/en/docs/install/#windows-stable

https://i.stack.imgur.com/dKAnr.png

then download and install. After close, the terminal then opens again and now is working.

https://i.stack.imgur.com/VznSx.png