112

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

valiano
  • 16,433
  • 7
  • 64
  • 79
Diptendu Das
  • 3,990
  • 7
  • 22
  • 38
  • 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. – Brian Lacy Jan 19 '22 at 16:18

17 Answers17

235

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

npm install -g yarn
kvantour
  • 25,269
  • 4
  • 47
  • 72
user1659644
  • 2,573
  • 3
  • 13
  • 11
  • this resolved my issue after installing yarn via choco (failed to run on yarn install) – Bama Dec 21 '19 at 18:20
  • 1
    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! – Imran_Developer Apr 19 '21 at 07:03
67

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.

Community
  • 1
  • 1
Dani Akash
  • 6,828
  • 3
  • 35
  • 47
29

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

General Grievance
  • 4,555
  • 31
  • 31
  • 45
bersu adane
  • 291
  • 3
  • 4
19

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!!!

Apurv Jha
  • 454
  • 3
  • 17
16

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.

Orlyyn
  • 2,296
  • 2
  • 20
  • 32
Onias da Rocha
  • 181
  • 3
  • 6
11

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\;

Eren Vardar
  • 111
  • 2
  • 4
  • 3
    for Windows after changing system environments you need to close and reopen the terminal – Oleg Polezky Feb 26 '20 at 04:10
  • 1
    In my case, Yarn was installed in `C:\Users\LAV\Username\Roaming\npm\node_modules\yarn\bin` and I added this to Path. I also had to close VSCode for the change to take effect. – Lars Nov 29 '22 at 11:00
9

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

jgritten
  • 915
  • 1
  • 11
  • 20
8

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

Prakash Reddy
  • 944
  • 10
  • 20
5

I faced same I did:

1.npm install -g yarn 

Then I faced this error *"yarn.ps1 cannot be loaded because running scripts is  disabled on this system. For more information, see about_Execution_Policies at.."*

        2.Go to C:\Users\<username>\AppData\Roaming\npm and delete yarn.ps1

        3. Then run -> yarn install
Vidhya
  • 79
  • 2
  • 6
4

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

Rajnikant Lodhi
  • 530
  • 4
  • 13
4

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

3

Try npx yarn start. This worked for me.

2

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

mustafa
  • 33
  • 1
  • 7
1

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

enter image description here

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

enter image description here

juanitourquiza
  • 2,097
  • 1
  • 30
  • 52
1

For some reason, in particular, yarn cannot be installed globally on my pc, but I have it installed on it. On MAC, I don't have this problem. I ran it locally to solve my specific problem, I don't recommend using it, but to get out of it quickly, you can run it NPX first "attention, you must have it installed before."

example: npx yarn install
Daniel
  • 373
  • 4
  • 10
1

I install yarn as following :

  1. in powershell env:
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted

this command will give you a correct execution policy

  1. npm install -g yarn
  2. yarn --version

Quoted from https://www.nextofwindows.com/fix-unable-to-run-yarn-in-windows-terminal-powershell

andrew.su
  • 31
  • 2
0

I had to add the path that npm config get prefix returned to my users PATH environmental variable.

tedi
  • 6,350
  • 5
  • 52
  • 67