想用expo-cli搭建一个react-native应用,结果刚安装好脚手架就出错了,expo不能执行。
C:\Users\wanghongxuan>expo
'expo' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
解决办法:win10环境(任何 “不是内部或外部命令,也不是可运行的程序或批处理文件。” 都可以使用以下方法)
如果是使用npm安装依赖的话,输入指令:npm config list
,找到prefix字段的值,是npm的路径,添加到环境变量就可以。如下图:
在这里,我使用的是yarn。使用yarn命令安装的话,输入指令:yarn global bin
,找到bin文件的文件路径,如下:
C:\Users\wanghongxuan>yarn global bin
warning package.json: No license field
C:\Users\wanghongxuan\AppData\Local\Yarn\bin //此处为文件路径
将bin文件的路径拷贝到Path环境变量中,保存。
Path环境变量:此电脑>鼠标右键:属性>高级系统设置>高级>环境变量>系统变量(S)>Path,
点击编辑按钮,新建环境变量,然后将bin文件路径复制到这里,保存。
注意:更改环境变量之后一定要重新开启命令行,然后执行命令,出现以下内容便是成功了。
C:\Users\wanghongxuan>expo
Usage: expo [options] [command]
Options:
-V, --version output the version number
-o, --output [format] Output format. pretty (default), raw
--non-interactive Fail, if an interactive prompt would be required to continue. Enabled by default if stdin is not a TTY.
-h, --help output usage information
Commands:
android [options] [project-dir] Opens your app in Expo on a connected Android device
build:ios|bi [options] [project-dir] Build a standalone IPA for your project, signed and ready for submission to the Apple App Store.
build:android|ba [options] [project-dir] Build a standalone APK or App Bundle for your project, signed and ready for submission to the Google Play Store.
build:web [options] [project-dir] Build a production bundle for your project, compressed and ready for deployment.
build:status|bs [options] [project-dir] Gets the status of a current (or most recently finished) build for your project.
bundle-assets [options] [project-dir] Bundles assets for a detached app. This command should be executed from xcode or gradle.
......