React-native: command not found 命令未找到

我在创建一个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并重新安装了它,但我仍然面临同样的问题。

355086 次浏览

将正确的路径添加到path变量后,问题就解决了。

下面是找到正确路径的步骤。

1. Enter: npm install -g react-native-cli
output: /usr/local/Cellar/node/6.1.0/libexec/npm/bin/react-native ->/usr/local/Cellar/node/6.1.0/libexec/npm/lib/node_modules/react-native-cli/index.js/usr/local/Cellar/node/6.1.0/libexec/npm/lib
└── react-native-cli@0.2.0

从上面的输出你可以清楚地看到路径:/usr/local/Cellar/node/6.1.0/libexec/npm/bin/react-native < / >强

export PATH="/usr/local/Cellar/node/6.1.0/libexec/npm/bin:$PATH"


react-native init appName


cd appName


react-native run-ios

如果您在此阶段得到xcrun: error: unable find utility "simctl",您可以使用以下步骤解决

XCode -> Preferences -> Locations -> Command Line Tools ->选择“XCode 7.2.1”

你可以从xrun无法找到simctl中找到原始的解决方案

感谢@fbozo

就是这样! !

我也有同样的问题,但你的方法有一半对我没用。 我以你的方式获取路径:从react-native-cli instal的输出,但手动在ect/ paths中写入:

sudo nano /etc/paths

在结束时,我已经添加了输出的路径,然后按CTRL x和y保存。 只有这种方法有效,但是非常感谢你的提示!< / p >

我有点傻,碰到了这个问题。我使用nvm来管理我的不同版本的节点,并将react-native安装到一个不是我默认的节点版本中。在打开一个新shell时,我失去了我的命令。:)当然是切换回固定的东西。

在不断地遇到这个问题,并击中这个答案,没有它的工作..

假设你不以root/sudo身份运行npm(你不应该这样做!)你的npm模块将被安装在不管你设置的默认目录是什么中。

假设您已经遵循了这些说明,并且默认目录是~/。Npm-global,然后需要添加~/。Npm-global /bin到您的路径。

这是在这些指令中概述的,但对我来说,我把它添加到.bashrc:

export PATH=$PATH:$HOME/.npm-global/bin

然后重新启动shell,它就可以工作了。

如果由于某些奇怪的原因,react-native的路径不在PATH中,你应该注意react-native可执行文件的安装位置。一般来说,command not found的问题是因为它们不在PATH中。

例如,我使用nodenv并运行npm install -g react-native

/Users/khoa/.nodenv/versions/10.10.0/bin/react-native -> /Users/khoa/.nodenv/versions/10.10.0/lib/node_modules/react-native/local-cli/wrong-react-native.js

所以我需要把它添加到我的PATH

export PATH=$HOME/.nodenv/versions/10.10.0/bin:$PATH

你可以用echo $PATH来验证

或者你可以使用npx来执行本地的npm模块

npx react-native run-ios --simulator='iPhone X'

运行这段代码

npm i -g react-native-cli

关闭CMD并再次打开它

首先在终端上运行这个命令。

npm i -g react-native-cli

然后通过这个命令创建您的react-native项目。

React-native init Project name

然后通过CD命令移动到项目目录。

以防有人遇到这个问题,我遇到过与qix类似的问题,但更微妙。

新的shell终端将默认为不同版本的节点。 我会把我的终端更改为我想要的节点,但是当bundle脚本运行时,它在一个新的shell中运行,并且它得到了没有安装react-native的默认版本

我使用了nvm alias default x.x.x,这样新的shell将继承我想要的默认版本。

使用npm install -g react-native-cli安装react-native-cli。 你可能需要像sudo npm install -g react-native-cli

这样使用sudo

如果谁有错误,试试sudo:

Sudo NPM install -g react-native-cli

尝试使用react-native -help,看看会出现什么。试着卷发

React原生库推荐:

如果你得到一个错误,如不能找到模块'npmlog',尝试直接安装npm: curl -0 -L https://npmjs.org/install.sh | sudo sh。

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

这真的很奇怪,在我这边(macOS 10.14),我很确定我的节点和npm工作,但我一直得到命令没有找到只有这个特定的包。最后我做了以下事情:

您现在可以在react-native-debugger中调试视图层次结构并查看控制台日志

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install yarn
brew install node
brew install watchman
brew tap AdoptOpenJDK/openjdk
brew cask install adoptopenjdk8
npm install -g react-native-cli

根据官方文件,下面的命令对我有用。

  • NPX react-native run-android

链接在这里

  • < a href = " https://facebook.github。Io /react-native/docs/getting-started" rel="nofollow noreferrer">https://facebook.github.io/react-native/docs/getting-started

我试图通过“react-native run-android”命令运行。确保在全局安装了react-native cli !

如果你正在使用,你可能必须在前面运行yarn命令。例子:

yarn react-native info

亲爱的,

请尝试:npm install -g react-native-cli

如果你得到一个像不能找到模块' npmlog '这样的错误,你可以直接使用这个命令安装npm。如果上述命令运行成功,则无需执行此命令

curl -0 -L https://npmjs.org/install.sh | sudo sh

# For_Ubuntu

致以最亲切的问候。

在cmd管理模式下,运行

NPM安装react-native-cli

使用以下命令全局安装react-native

npm i -g react-native-cli

试一试

npx react-native

如果不工作,安装全局

npm i -g react-native-cli

我做了一个npm更新,遇到了同样的错误,但在做了npm安装和重新构建应用程序工作!

我已经安装了react-nativereact-native-cli,只需要运行:

yarn install

我从世博会弹出后,忘记删除node_modules,并通过运行yarnnpm install重新安装。

在我这样做之后,然后运行npx react-native run-android,它工作得很好!