node.js “create-react-app”未被识别为内部或外部命令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38977255/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 20:30:00  来源:igfitidea点击:

'create-react-app' is not recognized as an internal or external command

node.jsreactjs

提问by U?ur Ye?ilyurt

I am trying to set up react app using create-react-app command on windows pc. I already used it on my mac computer, and it works well. But I encounter a problem. Here my steps on command line. Am i missing something?

我正在尝试在 windows pc 上使用 create-react-app 命令设置反应应用程序。我已经在我的 mac 电脑上使用过它,它运行良好。但是我遇到了一个问题。这是我在命令行上的步骤。我错过了什么吗?

C:\Windows\system32>cd C:\Users\ugur\Desktop\deneme

C:\Users\ugur\Desktop\deneme>npm init


This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.

See 'npm help json' for definitive documentation on these fields
and exactly what they do.

Use 'npm install <pkg> --save' afterwards to install a package and
save it as a dependency in the package.json file.

Press ^C at any time to quit.
name: (deneme)
version: (1.0.0)
description:
entry point: (index.js)
test command:
git repository:
keywords:
license: (ISC)
About to write to C:\Users\ugur\Desktop\deneme\package.json:

{
   "name": "deneme",
   "version": "1.0.0",
   "description": "",
   "main": "index.js",
   "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
   },
   "author": "Ugur <[email protected]> (http://www.abc.com.tr)",
   "license": "ISC"
}


Is this ok? (yes)

C:\Users\ugur\Desktop\deneme>npm install -g create-react-app
C:\Users\ugur\AppData\Roaming\npm\create-react-app -> C:\Users\ugur\
AppData\Roaming\npm\node_modules\create-react-app\index.js
C:\Users\ugur\AppData\Roaming\npm
`-- [email protected]
  +-- [email protected]
  | +-- [email protected]
  | +-- [email protected]
  | +-- [email protected]
  | | `-- [email protected]
  | +-- [email protected]
  | `-- [email protected]
  +-- [email protected]
  | +-- [email protected]
  | | +-- [email protected]
  | | `-- [email protected]
  | `-- [email protected]
  |   `-- [email protected]
  +-- [email protected]
  `-- [email protected]


C:\Users\ugur\Desktop\deneme>create-react-app new_app

'create-react-app' is not recognized as an internal or external command, operable program or batch file.

Also npm configuration path is like

另外 npm 配置路径就像

C:\Users\ugur\AppData\Roaming\npm\node_modules\create-react-app\

C:\Users\ugur\AppData\Roaming\npm\node_modules\create-react-app\

回答by Wathsala Karunathilake

Try with this npx create-react-app my-app

试试这个 npx create-react-app my-app

回答by U?ur Ye?ilyurt

I solved the problem by adding C:\Users\ugur\AppData\Roaming\npmto windows PATH variable.

我通过添加C:\Users\ugur\AppData\Roaming\npm到 Windows PATH 变量解决了这个问题。

回答by Shishay Ghebrehiwet

simply putting 'npx' in front of the command will solve this if you are running older version of node.

如果您运行的是较旧版本的节点,只需将“npx”放在命令前面即可解决此问题。

try this and it will work fine.

试试这个,它会正常工作。

npx create-react-app [yourProjectName]

npx create-react-app [yourProjectName]

回答by Josan Iracheta

I'm adding this because this pops up on Google and I was having trouble.

我添加这个是因为它在谷歌上弹出,我遇到了麻烦。

I'm on Windows 10 and I searched for 'create-react-app' in C:\and the path was C:\Users\Admin\AppData\Roaming\npm\node_modules.

我在 Windows 10 上搜索“create-react-app”,C:\路径是C:\Users\Admin\AppData\Roaming\npm\node_modules.

I added that to the Environment Variables > Path and the command works now.

我将其添加到 Environment Variables > Path 中,该命令现在可以使用了。

回答by Sourabh Dubey

First Check your Node version. if your node version is 8 or greater then 8 then use
'npx create-react-app my-app'

首先检查您的节点版本。如果您的节点版本为 8 或更高,则使用
'npx create-react-app my-app'

In the above version we need to change only one word that is npx

在上面的版本中我们只需要改变一个词就是npx

You don't need to do another things. I hope this will help you

你不需要做其他事情。我希望这能帮到您

回答by Vick Sain

I also get same problem but I resolve it by following steps

我也遇到同样的问题,但我按照以下步骤解决了

  1. Check your global directory by using command npm root -g
  2. check the folder, will it have .cmdof your installed packages.
  3. If yes, Please copy the path of folder and put in path of user variables.
  1. 使用命令npm root -g检查您的全局目录
  2. 检查文件夹,它是否包含已安装软件包的.cmd
  3. 如果是,请复制文件夹路径并放入用户变量路径。

Thanks

谢谢

回答by Marina ES

  • Run : npx install create-react-app nameOfYourFolderinstead of npm install create-react-app nameOfYourFolder(npx comes with npm 5.2+ and higher)
  • Then : cd nameOfYourFolder
  • Then run : npm start
  • 运行 :npx install create-react-app nameOfYourFolder而不是npm install create-react-app nameOfYourFolder(npx 带有 npm 5.2+ 及更高版本)
  • 然后 : cd nameOfYourFolder
  • 然后运行: npm start

You can find more in React documentation here

您可以在此处的React 文档中找到更多信息

回答by Jim

I had to add c:\node_modules.bin to my path to run create-react-app

我必须将 c:\node_modules.bin 添加到我的路径中才能运行 create-react-app

Do a search for create-react-app and use that in your path.

搜索 create-react-app 并在您的路径中使用它。

回答by Jacman

Do the following from TERMINAL:

执行以下操作TERMINAL

  • cd myReactApp
  • npx create-react-app .
  • cd myReactApp
  • npx create-react-app .

This should work!

这应该有效!

回答by ADARSH KUNWAR

Use npx create-react-app my-app. This will solve any issue with the system path variable.

使用npx create-react-app my-app. 这将解决系统路径变量的任何问题。

React GitHub documentation suggests this as well. Read Here

React GitHub 文档也建议了这一点。在这里阅读