无法使用 npx create-react-app 创建 React 应用程序

Can´t create react app using npx create-react-app

我是 React 新手,但我已经创建了一些应用程序,但今天当我尝试创建一个新应用程序时,它就是行不通。我使用的是 Node 版本 v15.6.0 和 npm 7.4.0。 我的操作系统是 Windows 10.

我正在处理的文件树:C: Users\kryst\Documents\test-app\app\package.JSON

但是当我在 C: Users\kryst\Documents\test-app 目录中 运行 npx create-react-app app 时,它会抛出这些消息。

PS C:\Users\kryst\Documents\test-app> npx create-react-app app

You are running `create-react-app` 4.0.1, which is behind the latest release (4.0.2).

We no longer support global installation of Create React App.

Please remove any global installs with one of the following commands:
- npm uninstall -g create-react-app
- yarn global remove create-react-app
The latest instructions for creating a new app can be found here:

npm ERR! code 1
npm ERR! path C:\Users\kryst\Documents\test-app
npm ERR! command failed
npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c create-react-app app

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\kryst\AppData\Local\npm-cache\_logs21-02-07T09_22_38_962Z-debug.log

我已经尝试过 npm cache clean --force ,重新安装整个应用程序并重新启动计算机。

你知道如何解决这个问题吗?我将不胜感激。

npm install -g create-react-app --force

解决方案已在错误日志中:

1-您已经在您的机器上全局安装了 create-react-app,因此请使用以下命令之一删除所有全局安装:

  npm uninstall -g create-react-app
  yarn global remove create-react-app

2-如果您想创建一个应用程序,只需输入:

npx create-react-app your_app_name

这将使 npx 从 npm 注册表中获取 create-react-app 并在本地 运行 它而不安装它。

npm 7.0.0 开始,npx 二进制文件是 rewritten

the --ignore-existing option is removed. Locally installed bins are always present in the executed process PATH.

所以之前缓存的二进制文件总是先调用,现在我们必须明确说明我们对包版本的意图(只需在包名称中添加 @latest):

npx create-react-app@latest app

或者,如果您想从缓存中删除旧版本,只需清除 _npx 文件夹即可。您可以使用 npm get cache 命令找到它的位置。