【问题标题】:zsh: command not found: react-native - MacOSzsh:找不到命令:react-native - MacOS
【发布时间】:2023-03-04 09:28:01
【问题描述】:

我正在尝试启动 react-native,但是当我写 react-native init firstApp 时出现以下错误 zsh: command not found: react-native .

我尝试了以下指南:react-native: command not found

但我有两个主要问题:

第一 我不明白使用/导出哪个路径

这里已经安装了 React-native:

/Users/cisco/.npm-packages/bin/react-native -> /Users/cisco/.npm-packages/lib/node_modules/react-native/local-cli/wrong-react-native.js 

第二

在指南中它被写入运行:

export PATH="/usr/local/Cellar/node/6.1.0/libexec/npm/bin:$PATH"   
react-native init appName  
cd appName   
react-native run-ios

我不知道怎么做:

1)export PATH=之后写什么

2) 我应该在某处添加我的路径吗?如果是,我该怎么做? 我尝试运行touch ~/.bash_profile; open ~/.bash_profile 来添加我的路径。

里面有:

# added by Anaconda3 5.3.1 installer
# >>> conda init >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$(CONDA_REPORT_ERRORS=false '/anaconda3/bin/conda' shell.bash hook 2> /dev/null)"
if [ $? -eq 0 ]; then
    \eval "$__conda_setup"
else
    if [ -f "/anaconda3/etc/profile.d/conda.sh" ]; then
        . "/anaconda3/etc/profile.d/conda.sh"
        CONDA_CHANGEPS1=false conda activate base
    else
        \export PATH="/anaconda3/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda init <<<
# added by Anaconda3 2018.12 installer
# >>> conda init >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$(CONDA_REPORT_ERRORS=false '/Users/cisco/anaconda3/bin/conda' shell.bash hook 2> /dev/null)"
if [ $? -eq 0 ]; then
    \eval "$__conda_setup"
else
    if [ -f "/Users/cisco/anaconda3/etc/profile.d/conda.sh" ]; then
        . "/Users/cisco/anaconda3/etc/profile.d/conda.sh"
        CONDA_CHANGEPS1=false conda activate base
    else
        \export PATH="/Users/cisco/anaconda3/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda init <<<

一旦你帮我确定了正确的添加路径,我可以简单地将它添加到# <<< conda init <<<? 行下面的文件中

【问题讨论】:

  • 您是否尝试为 react-native 提供完整路径
  • 你安装了 react-native-cli - npm install -g react-native-cli
  • 是的,我确实安装了npm install -g react-native-cli
  • 好吧,sudo npm install -g react-native-cli 为我完成了这项工作。

标签: macos react-native


【解决方案1】:

解决了!

步骤:

  1. 运行npm list -g | head -n 1

它会给你一个类似/类似以下的路径:/Users/{YOUR_USER_NAME}/.npm-packages/lib

  1. 通过将/lib 替换为/bin:$PATH 来更改该路径,以便您获得:/Users/cisco/.npm-packages/bin:$PATH

  2. 运行export PATH="/Users/{YOUR_USER_NAME}/.npm-packages/bin:$PATH"

【讨论】:

    【解决方案2】:

    由于您使用的是 zsh。你可以在 ~/.zshrc 中添加export PATH=/Users/cisco/.npm-packages/bin/react-native:$PATH

    【讨论】:

    • 我做了以下stt ~/.zshrc 并添加了export PATH=/usr/local/Cellar/node/6.1.0/libexec/npm/bin:$PATH 行,但我得到了同样的信息。
    • 你可以试试这个/Users/cisco/.npm-packages/bin/react-native我编辑了我的答案
    • 你能确认这个文件/Users/cisco/.npm-packages/bin/react-native存在吗?
    【解决方案3】:

    这个手术对我很有效。只需按照以下说明操作即可。

    默认的交互式 shell 现在是 zsh。 要更新您的帐户以使用 zsh,请运行

    chsh -s /bin/zsh
    

    【讨论】:

      猜你喜欢
      • 2019-03-05
      • 2021-12-02
      • 2020-09-04
      • 2020-02-06
      • 2022-08-17
      • 1970-01-01
      • 2020-03-03
      • 2016-09-08
      相关资源
      最近更新 更多