node.js create-react-app,安装错误(“找不到命令”)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38751830/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
create-react-app, installation error ("command not found")
提问by Paulos3000
I have installed create-react-app exactly as instructed on the facebook instruction page (https://facebook.github.io/react/blog/2016/07/22/create-apps-with-no-configuration.html):
我已经完全按照 Facebook 说明页面(https://facebook.github.io/react/blog/2016/07/22/create-apps-with-no-configuration.html)上的指示安装了 create-react-app :
First, install the global package:
npm install -g create-react-app
首先,安装全局包:
npm install -g create-react-app
I did this. It appeared to work fine - the file was installed to
我这样做了。它似乎工作正常 - 该文件已安装到
users/*name*/.node_modules_global/lib/node_modules/create-react-app
I'm not really sure why global install takes it to this path, but there you have it.
我不太确定为什么 global install 将它带到这个路径,但是你已经知道了。
Next instruction:
下一条指令:
Now you can use it to create a new app:
create-react-app hello-world
现在你可以用它来创建一个新的应用程序:
create-react-app hello-world
Couldn't be simpler, right? But Terminal spits out this at me:
不能更简单,对吧?但终端向我吐槽:
-bash: create-react-app: command not found
It's probably something very simple I'm missing but I don't really know where to look. If anyone can help I'd really appreciate it!
这可能是我想念的非常简单的东西,但我真的不知道去哪里找。如果有人可以帮助我真的很感激!
Thanks in advance.
提前致谢。
Note: I'm using Node v6.3.1, and npm v3.10.3
注意:我使用的是 Node v6.3.1 和 npm v3.10.3
采纳答案by Dan Abramov
Your Node setup looks incorrect. It's not an issue with Create React App—it seems like you can't run any global Node commands.
您的节点设置看起来不正确。这不是 Create React App 的问题——似乎您无法运行任何全局节点命令。
It looks like ~/.node_modules_global/binis not in your PATHenvironment variable so it can't execute global commands. That's just how Bash works—it can't guess where the command lies, you need to tell it. I would assume Node installation should do this by default but it depends on how you installed Node.
它看起来~/.node_modules_global/bin不在您的PATH环境变量中,因此无法执行全局命令。这就是 Bash 的工作原理——它无法猜测命令在哪里,你需要告诉它。我认为 Node 安装应该默认执行此操作,但这取决于您如何安装 Node。
So make sure that directory is in your PATHand try again. If you use Bash, add this to your .profileand then restart the Terminal:
因此,请确保该目录在您的目录中,PATH然后重试。如果您使用 Bash,请将其添加到您的.profile,然后重新启动终端:
export PATH=$HOME/.node_modules_global/bin:$PATH
回答by Hamdi Bayhan
You are able to apply the following solution:
您可以应用以下解决方案:
$ npm config set prefix /usr/local
$ sudo npm install -g create-react-app
$ create-react-app my-app
回答by Monil Bansal
The environment variables are not set properly.
When you run the create-react-appit shows you a path along with the error. Copy that path and add it in the environment variable.
环境变量设置不正确。当您运行create-react-app它时,它会显示一个路径以及错误。复制该路径并将其添加到环境变量中。
Alternatively you can use the command:
或者,您可以使用以下命令:
npx create-react-app <app_name>.
This will do the work for you.
这将为您完成工作。
回答by Michael Neely
Try this. It worked or me. I found this in the React documentation. "Npx" is not a typo. It's a package runner tool that comes with npm 5.2+.
尝试这个。它工作或我。我在 React 文档中找到了这个。“Npx”不是拼写错误。它是 npm 5.2+ 附带的包运行工具。
npx create-react-app my-app
npx create-react-app my-app
回答by ssareen
Use npxinstead of npm.
使用npx代替npm。
Check this out-> https://reactjs.org/docs/create-a-new-react-app.html#create-react-app
看看这个-> https://reactjs.org/docs/create-a-new-react-app.html#create-react-app
回答by Ishtiyaq Ali
I tried all methods listed above and in other sites. They weren't working for me. But for some reason I decided to addthe create-react-app directoryinto my system variablesas a last ditch method and to my surprise this actually worked.
我尝试了上面和其他网站上列出的所有方法。他们不是对我来说有效。但由于某些原因,我决定添加了创建反应的-app目录到我的系统变量作为最后挣扎的方法让我吃惊这个实际工作。
回答by Vinay Kumar
Answers given above are wright but wanna share somethings that i also face and these are basics ================To setup react project ============================
上面给出的答案是正确的,但想分享一些我也面临的问题,这些是基础知识 ================设置反应项目 ============== ================
If wanna create a node environment
如果想创建一个节点环境
$ sudo apt-get update
$ sudo apt-get install nodejs
(sometime we can also use but sudo means install in system level $apt-get nodeenv)
(有时我们也可以使用,但 sudo 意味着安装在系统级别 $apt-get nodeenv 中)
$ sudo apt-get install nodeenv
$ nodeenv env
$ source /bin/activate
If wanna create new react app then
如果想创建新的反应应用程序然后
$ npm install create-react-app
if error occurs create-react-app: command not found then install with -g, its happens because node is install globally and it is not
getting the node in local
如果发生错误 create-react-app: command not found 然后用 -g 安装,这是因为 node 是全局安装的,而不是
在本地获取节点
$ npm install -g create-react-app
$ create-react-app app_name
$ cd app_name
app_name$ npm start
回答by Uddesh_jain
I hope you already installed Node package manager(npm).
now run npm install -g create-react-app, if everything fine then you can use create-ract-appcommand.
if you are getting any permission error just sudo npm install -g create-react-app.
我希望你已经安装了 Node 包管理器(npm)。现在运行npm install -g create-react-app,如果一切正常,那么您可以使用create-ract-app命令。如果您收到任何权限错误sudo npm install -g create-react-app。
I hope it will work. Happy Hacking.
我希望它会起作用。快乐黑客。
回答by Mitchell Hudson
I am having the same problem and this solution did not work for me. I have:
我遇到了同样的问题,这个解决方案对我不起作用。我有:
export PATH=$HOME/.node_modules_global/bin:$PATH
export PATH=$HOME/.node_modules_global/bin:$PATH
in .bash_profile
在 .bash_profile 中
Currently echo $PATH shows:
目前 echo $PATH 显示:
/Users/username/.node_modules_global/bin:/Users/username/.rvm/gems/ruby-2.1.6/bin:/Users/username/.rvm/gems/ruby-2.1.6@global/bin:/Users/username/.rvm/rubies/ruby-2.1.6/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/username/.rvm/bin
/Users/username/.node_modules_global/bin:/Users/username/.rvm/gems/ruby-2.1.6/bin:/Users/username/.rvm/gems/ruby-2.1.6@global/bin:/Users/username/.rvm/rubies/ruby-2.1.6/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/username/.rvm/bin
If I go to Home I can see .npm and .npm-global. There is a an alias to create-react-app at .npm-global/bin/ and a folder at
如果我去主页,我可以看到 .npm 和 .npm-global。在 .npm-global/bin/ 有一个 create-react-app 的别名和一个文件夹在
.npm-global/lib/node_modules/create-react-app
.npm-global/lib/node_modules/create-react-app

