【问题标题】:Can´t create react app using npx create-react-app无法使用 npx create-react-app 创建反应应用程序
【发布时间】:2021-02-07 09:37:10
【问题描述】:

我是新手,但我已经创建了一些应用程序,但是今天当我尝试创建一个新应用程序时,它只是不起作用。我正在使用 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\_logs\2021-02-07T09_22_38_962Z-debug.log

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

您知道如何解决这个问题吗?我会很感激任何事情。

【问题讨论】:

    标签: javascript node.js reactjs npm create-react-app


    【解决方案1】:

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

    --ignore-existing 选项已删除。本地安装的 bin 始终存在于执行的进程 PATH 中。

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

    npx create-react-app@latest app
    

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

    【讨论】:

    • 非常感谢您的帮助!
    • 清除 _npx 文件夹的内容对我来说效果很好。
    【解决方案2】:
    npm install -g create-react-app --force
    

    【讨论】:

      【解决方案3】:

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

      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 并在本地运行它而不安装它。

      【讨论】:

      • 我没有全局安装create-react-app。但即使我运行卸载命令并再次尝试它也不起作用。奇怪的是,当我尝试全局安装它然后运行npx create-react-app 时,它起作用了。所以我不知道发生了什么以及为什么,但是按照与我被告知的完全相反的方式解决了问题。
      猜你喜欢
      • 2022-10-20
      • 1970-01-01
      • 2020-09-16
      • 1970-01-01
      • 2020-10-31
      • 2022-07-31
      • 1970-01-01
      • 2019-11-29
      • 2021-11-27
      相关资源
      最近更新 更多