create-react-app,安装错误("找不到命令")

Pau*_*000 22 facebook node.js npm reactjs

我已按照facebook说明页面(https://facebook.github.io/react/blog/2016/07/22/create-apps-with-no-configuration.html)的说明安装了create-react-app :

首先,安装全局包:

npm install -g create-react-app

我这样做了 它似乎工作正常 - 文件已安装到

users/*name*/.node_modules_global/lib/node_modules/create-react-app
Run Code Online (Sandbox Code Playgroud)

我不确定为什么全局安装会把它带到这条路上,但是你有它.

下一条指令:

现在您可以使用它来创建新的应用程序:

create-react-app hello-world

不能简单,对吧?但终端向我吐出这个:

-bash: create-react-app: command not found
Run Code Online (Sandbox Code Playgroud)

这可能很简单,我很遗憾,但我真的不知道在哪里看.如果有人可以提供帮助,我真的很感激!

提前致谢.

注意:我使用的是Node v6.3.1和npm v3.10.3

Ham*_*han 34

您可以应用以下解决方案:

$ npm config set prefix /usr/local
$ sudo npm install -g create-react-app
$ create-react-app my-app
Run Code Online (Sandbox Code Playgroud)


Dan*_*mov 19

您的节点设置看起来不正确 这不是Create React App的问题 - 看起来你无法运行任何全局Node命令.

它看起来~/.node_modules_global/bin不在您的PATH环境变量中,因此它无法执行全局命令.这就是Bash的工作方式 - 它无法猜出命令所在的位置,你需要告诉它.我假设Node安装应该默认执行此操作,但这取决于您安装Node的方式.

因此,请确保您的目录在您的位置,PATH然后重试.如果您使用Bash,请将其添加到您的.profile,然后重新启动终端:

export PATH=$HOME/.node_modules_global/bin:$PATH
Run Code Online (Sandbox Code Playgroud)


小智 11

环境变量设置不正确。运行时,create-react-app它会显示一条路径以及错误。复制该路径并将其添加到环境变量中。

或者,您可以使用以下命令:

npx create-react-app <app_name>.
Run Code Online (Sandbox Code Playgroud)

这将为您完成工作。


小智 7

尝试这个。它工作或我。我在 React 文档中找到了这个。“Npx”不是拼写错误。它是 npm 5.2+ 附带的包运行工具。

npx create-react-app my-app


Kas*_*hif 6

2020年12月17日

安装 Nodejs 和 npm

sudo apt update
sudo apt install nodejs
sudo apt install npm
Run Code Online (Sandbox Code Playgroud)

如果你安装,可能会显示类似 Reactjs 设置错误的信息。这对你有帮助

npm install -g create-react-app


npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /usr/local/lib/node_modules/create-react-app
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/create-react-app'
npm ERR!  [Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/create-react-app'] {
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'mkdir',
npm ERR!   path: '/usr/local/lib/node_modules/create-react-app'
npm ERR! }
npm ERR! 
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR! 
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/user/.npm/_logs/2020-12-17T14_16_02_442Z-debug.log
Run Code Online (Sandbox Code Playgroud)

然后当你在这之后输入

create-react-app test-react-app 
Run Code Online (Sandbox Code Playgroud)

在终端 zsh 中显示:命令未找到:create-react-app

您可以使用此命令修复此错误

sudo npm install -g create-react-app
create-react-app test-react-app
Run Code Online (Sandbox Code Playgroud)

我希望你也能工作顺利。