'create-react-app'不被识别为内部或外部命令

Uğu*_*urt 24 node.js reactjs

我试图在Windows PC上使用create-react-app命令设置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 <ugur@abc.com.tr> (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
`-- create-react-app@0.2.0
  +-- chalk@1.1.3
  | +-- ansi-styles@2.2.1
  | +-- escape-string-regexp@1.0.5
  | +-- has-ansi@2.0.0
  | | `-- ansi-regex@2.0.0
  | +-- strip-ansi@3.0.1
  | `-- supports-color@2.0.0
  +-- cross-spawn@4.0.0
  | +-- lru-cache@4.0.1
  | | +-- pseudomap@1.0.2
  | | `-- yallist@2.0.0
  | `-- which@1.2.10
  |   `-- isexe@1.1.2
  +-- minimist@1.2.0
  `-- semver@5.3.0


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.
Run Code Online (Sandbox Code Playgroud)

还有npm配置路径

C:\ Users \用户UGUR \应用程序数据\漫游\ NPM \node_modules \创建反应的应用内\

Uğu*_*urt 41

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

  • 谢谢,我发现它已经在我的PATH中,但我仍然得到同样的错误.我使用的是Windows 10. (4认同)
  • 听起来可能很愚蠢,但是在将上述内容添加到我的 Window PATH 变量之后,我发现关闭我试图在其上执行此命令的所有终端并重新打开它们很有帮助。重置终端会话是不够的。 (2认同)

小智 32

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

  • 给您点赞成票,因为从技术上来说,这是正确的答案,至少对我而言。(这很好)。 (4认同)
  • 你应该全局安装 create reat app 命令,如 &gt;npm install -g create-react-app (2认同)

Jos*_*eta 9

我正在添加这个,因为这出现在谷歌上,我遇到了麻烦.

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

我将它添加到Environment Variables> Path并且该命令现在可以正常工作.


小智 9

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

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

npx create-react-app [yourProjectName]


小智 8

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

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


小智 6

另一种可能有效的方法是使用 Powershell 并键入:

npx create-react-app new_app --use-npm
Run Code Online (Sandbox Code Playgroud)


Sou*_*bey 5

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

在以上版本中,我们只需要更改一个单词npx

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


Sid*_*Sid 5

尽管我遇到了同样的问题

npm install create-react-app --global
Run Code Online (Sandbox Code Playgroud)

后来尝试过

npm init react-app projectname
Run Code Online (Sandbox Code Playgroud)

这对我有用,它创建了一个 React 项目。这也有效

npx create-react-app projectname
Run Code Online (Sandbox Code Playgroud)