androidnpmreact-nativeyarnpkg

How do I create a React Native project using Yarn?


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 $? 

Solution

  • 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