48

I am running the following commands in the DOS console on a Windows 7 (64-bit) machine.

npm install -g yarn
yarn add global react-native
yarn add global react-native-cli

react-native init sample

After running react-native init sample, the console was closed.

The error log shows:

D:\Mobile>"$basedir/../../Users/pramaswamy/AppData/Local/Yarn/.global/node_modules/.bin/react-native.cmd"   "$@" 

D:\Mobile>exit $? 
Aurora0001
  • 13,139
  • 5
  • 50
  • 53
Prabhakaran Ramaswamy
  • 25,706
  • 10
  • 57
  • 64

7 Answers7

62

I think you're adding global dependencies wrong, and you shouldn't need to install react-native, globally or locally. react-native init will create a package.json with react-native listed as a dependency.

You should be able to install react-native-cli globally with yarn global add react-native-cli, not yarn add global react-native-cli.

Here yarn run android command will be used to run the react native app using yarn package manager, and yarn start will start the node JS server.

You should be fine with running the following:

npm install -g yarn
yarn global add react-native-cli
react-native init sample
yarn run android
yarn start
Dean
  • 7,814
  • 8
  • 30
  • 31
Jason Turner
  • 829
  • 6
  • 3
  • 2
    Note that Yarn discourage installing yarn via npm as of now. – Chris Gomez Sep 30 '17 at 18:44
  • 4
    react-native-cli is outdated – stackdave Oct 22 '18 at 12:54
  • The React Native docs state: "If you previously installed a global *react-native-cli* package, please remove it as it may cause unexpected issues." https://reactnative.dev/docs/environment-setup#creating-a-new-application – ChrisW May 20 '21 at 10:17
20

NEW SEP 2019, now it's more simple, use node10 and expo: (easy way)

npm install -g expo-cli

*to create project:

    expo init AwesomeProject

    cd AwesomeProject
    npm start

*install the app 'expo' on your phone, and scan the qr code for the project and you can start to view your app

more info: https://facebook.github.io/react-native/docs/getting-started.html

UPDATE OCT 2018 Create React Native App (now discontinued) has been merged with Expo CLI You can now use expo init to create your project. See Quick Start in the Expo documentation for instructions on getting started using Expo CLI.

Unfortunately, react-native-cli is outdated. Starting 13 March 2017, use create-react-native-app instead. Moreover, you shouldn't install Yarn with NPM. Instead, use one of the methods on the yarn installation page.

1. Install yarn

Via NPM. According to its installation docs, you shouldn't install yarn via npm, but if necessary, you can still install it with a pre-v5 version of npm.


UPDATE 2018 - OCTOBER

Node 8.12.0 and NPM 6.4.1 is already compatible with create-react-native-app. Really some minors previous versions too. You don't need more downgrade your npm.

On Ubuntu.

curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list

On macOS, use Homebrew or MacPorts.

brew install yarn
sudo port install yarn

2. Install the Create React Native App

yarn global add create-react-native-app

3. Update your shell environment

source ~/.bashrc

4. Create a React native project

create-react-native-app myreactproj

stackdave
  • 6,655
  • 9
  • 37
  • 56
8

You got the order wrong. You should be

yarn add global react-native-cli
yarn add react-native
react-native init sample
nikjohn
  • 20,026
  • 14
  • 50
  • 86
2

Please You visit Bug

yarn global add react-native-cli

with

react-native --version

and I get "$basedir/../../Users/juvasquezg/AppData/Local/Yarn/config/global/node_modules/.bin/react-native.cmd" "$@"

the system cannot find the path specified

Go to C:\Program Files\nodejs and I saw:

  • react-native
  • react-native.cmd
  • react-native.cmd.cmd

The fix is to delete react-native.cmd and rename react-native.cmd.cmd to react-native.cmd

The Solution #1324 (comment)

Fruchtzwerg
  • 10,999
  • 12
  • 40
  • 49
juvasquezg
  • 117
  • 2
  • 11
2

If you want to create app using yarn instead of npx;

yarn dlx react-native init ExampleApp this command will be helpful.

According to the react native documentation we should use npx react-native init AwesomeProject command

For more info about "yarn dlx": https://yarnpkg.com/cli/dlx

Yarn global is deprecated. If you run yarn global you will get an error.

enter image description here

Usage Error: The 'yarn global' commands have been removed in 2.x - consider using 'yarn dlx' or a third-party plugin instead

But yarn dlx won't work like yarn global or npm install <module> --global

Lojith Vinsuka
  • 906
  • 1
  • 10
  • 8
1

It is now:

yarn dlx create-react-native-app

then follow the instructions.

cd project_name into the project folder and do:

yarn install

then try with:

yarn web
Tim4497
  • 340
  • 3
  • 19
1

You could also do

yarn dlx expo-cli

then:

expo init project_name

and follow the instructions

after finishing cd project_name and try

yarn web
Tim4497
  • 340
  • 3
  • 19