如何使用Yarn创建React Native项目?

Pra*_*ran 30 android npm react-native yarnpkg

我在Windows 7(64位)计算机上的DOS控制台中运行以下命令.

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

react-native init sample
Run Code Online (Sandbox Code Playgroud)

运行后react-native init sample,控制台已关闭.

错误日志显示:

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

D:\Mobile>exit $? 
Run Code Online (Sandbox Code Playgroud)

小智 34

我认为你添加的全局依赖项是错误的,你不需要在react-native全局或本地安装.react-native init将创建一个package.json具有react-native作为依赖上市.

您应该能够react-native-cli全局安装yarn global add react-native-cli,而不是yarn add global react-native-cli.

运行以下内容应该没问题:

npm install -g yarn
yarn global add react-native-cli
react-native init sample
Run Code Online (Sandbox Code Playgroud)

  • react-native-cli 已过时 (3认同)
  • 请注意,Yarn目前不鼓励通过npm安装纱线. (2认同)

sta*_*ave 18

2018年10月更新创建React Native App(现已停止)已与Expo CLI合并您现在可以使用expo init创建项目.有关入门使用Expo CLI的说明,请参阅Expo文档中的"快速入门".

不幸的是,react-native-cli已经过时了.从2017年3月13日开始,请create-react-native-app改用.此外,您不应该使用NPM安装Yarn.而是使用yarn 安装页面上的方法之一.

1.安装 yarn

通过NPM.根据其安装文档,您不应该安装yarnvia npm,但如果有必要,您仍然可以使用v5之前的版本安装它npm.

brew install yarn

2018年更新 - 10月

节点8.12.0和NPM 6.4.1已与create-react-native-app兼容.真的是一些未成年人以前的版本.您不需要更多降级你的npm.

在Ubuntu上.

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
Run Code Online (Sandbox Code Playgroud)

在macOS上,使用Homebrew或MacPorts.

sudo port install yarn
yarn global add create-react-native-app

2.安装Create React Native App

source ~/.bashrc

3.更新shell环境

create-react-native-app myreactproj

4.创建React本机项目

react-native-cli


nik*_*ohn 8

你的订单错了.你应该

yarn add global react-native-cli
yarn add react-native
react-native init sample
Run Code Online (Sandbox Code Playgroud)