我在创建react-native项目的同时获得了 -bash: react-native: command not found error .
以下是其他信息
1. brew --version
homebrew 0.9.9
2 brew info watchman
watchman `enter code here`stable 4.50
/usr/local/Cellar/watchman/4.4.0
3. brew info flow
stable 0.24.1
/usr/local/Cellar/flow/0.24.1
4. brew info node
stable 6.1.0
/usr/local/Cellar/node/6.1.0
5. npm -version
3.8.6
6. echo $PATH
/Users/Ashok/.rbenv/shims:/Users/Ashok/.rbenv/shims:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
我尝试从下面的链接建议的步骤,但我仍然得到相同的错误 .
我没有他们在解决方案中指定的任何“npm”目录
Ashoks-MacBook-Pro:share Ashok$ ls
aclocal doc info ruby-build zsh
autoconf emacs man systemtap
但我发现npm文件存在于以下位置 .
/usr/local/Cellar/node/6.1.0/etc/bash_completion.d
我卸载了react-native并再次安装,但我仍面临同样的问题 .
5 回答
经过不断遇到这个问题,并得到这个答案,没有它的工作..
假设你没有做!)你的npm模块将安装在whatever you set your default directory to be中 .
假设您已按照这些说明操作,并且您的默认目录为〜/ .npm-global,那么您需要在路径中添加〜/ .npm-global / bin .
这些说明中概述了这一点,但对我来说,我将其添加到.bashrc中:
然后重启你的shell,它会工作 .
我有点傻了,遇到了这个问题 . 我使用nvm来管理我的不同版本的节点,并将react-native安装到不是我的默认节点的节点版本中 . 打开一个新shell后,我失去了命令 . :)切换当然固定的东西 .
在向PATH变量添加正确路径后,问题得以解决 .
以下是找到正确路径的步骤 .
从上面的输出你可以清楚地看到路径: /usr/local/Cellar/node/6.1.0/libexec/npm/bin/react-native
如果你在这个阶段得到 xcrun: error: unable to find utility "simctl" ,你可以使用以下步骤重新开始
XCode - >首选项 - >位置 - >命令行工具 - >选择Xcode 7.2.1
你可以找到xcrun unable to find simctl的原始解决方案
感谢@fbozo
而已!!!
有同样的问题,但你的一半方法不适合我 . 我按照您的方式采取了路径:从react-native-cli安装的输出,然后手动在ect / pathes中写入:
最后我添加了从输出到ctrl x和y的路径来保存 . 只有这种方式有效,但非常感谢线索!
如果由于某些奇怪的原因,
react-native
的路径不在PATH
中,您应该注意react-native
可执行文件的安装位置 . 通常,command not found
的问题是因为它们不在PATH
中 .例如,我使用
nodenv
并运行npm install -g react-native
所以我需要将它添加到我的
PATH
export PATH=/Users/$HOME/.nodenv/versions/10.10.0/bin:$PATH
您可以使用
echo $PATH
进行验证或者,您可以使用npx来执行本地npm模块