【问题标题】:create-react-app not currently workingcreate-react-app 当前不工作
【发布时间】:2016-12-23 04:26:30
【问题描述】:

我跑了npm install create-react-app -g 然后

create-react-app hello-world

返回

-bash: create-react-app: command not found

我了解我的$PATH 目前搞砸了。这是echo $PATH返回的内容

/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin

我真的不知道将其设置为什么,因为我目前对终端非常陌生。任何帮助将不胜感激。谢谢!

【问题讨论】:

标签: reactjs terminal path create-react-app


【解决方案1】:

只需将路径导出到 .bashrc,然后从 $Home 目录中的 .profile 文件中调用它,然后重新启动。例如: .bashrc 文件:

export PATH=$HOME/node_modules/.bin/:$PATH

.profile 文件:

# if running bash
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
       . "$HOME/.bashrc"
    fi
fi

 # set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi

【讨论】:

    【解决方案2】:

    所以我最近一直遇到这个问题,这是因为我刚刚输入了create-react-app [app-name]。

    如果有人再次遇到此问题,请输入npx create-react-app [app-name]、npm init react-app [app-name] 或yarn create react-app [app-name]。

    https://facebook.github.io/create-react-app/docs/getting-started

    希望对某人有所帮助!

    【讨论】:

      【解决方案3】:

      我不能 100% 确定您的问题的答案。然而;如果你只是想设置一个 React 环境,我建议参考 React 的 Youtube 教程。 在所需目录上创建一个文件夹,然后使用命令提示符、gitBash 或 Cygwin 转到特定目录,并使用 NodeJs 安装开始所需的一切。按照前 10 分钟进行设置,然后你就可以了去。祝你好运

      https://www.youtube.com/watch?v=IR6smI_YJDE&t=278s&list=PLbeWHDJFd79RXvAeGaDXMmxL_tkb3MvdH&index=1

      【讨论】:

        【解决方案4】:

        将 npm-packages 添加到 .bash_profile 中的路径

        echo 'export PATH="$HOME/.npm-packages/bin:$PATH"' >> ~/.bash_profile
        source ~/.bash_profile
        

        【讨论】:

          【解决方案5】:

          我遇到了同样的问题,虽然长期修复可以修复 $PATH,但我可以为您提供“快速而肮脏”的方式来启动您的 create-react-app。

          这是我安装 create-react-app 后得到的输出,我使用了使用命令的路径

          BatMan-MacBook-Pro:coursera-react batman$ sudo npm install -g create-react-app
          
          /Users/batman/.npm-packages/bin/create-react-app -> /Users/batman/.npm-packages/lib/node_modules/create-react-app/index.js
          + create-react-app@2.1.1
          updated 1 package in 2.594s
          

          我使用上面的路径来实现它并且它起作用了。

          BatMan-MacBook-Pro:coursera-react batman$ /Users/batman/.npm-packages/bin/create-react-app BatManCafe
          

          【讨论】:

            猜你喜欢
            • 2019-03-13
            • 1970-01-01
            • 2019-09-19
            • 2021-12-03
            • 1970-01-01
            • 2019-10-01
            • 2022-12-06
            • 2019-11-19
            • 2022-01-22
            相关资源
            最近更新 更多