【问题标题】:npx create-react-app 提示全局卸载不存在的 create-react-app 包?
【发布时间】:2022-01-17 23:29:33
【问题描述】:

我遇到了涉及全局安装的 npx create-react-app 问题。我的困惑是因为据我所知我的机器上没有安装 create-react-app 包。

一些细节:

我开始了一个 react 项目(使用 typescript 模板),就像我之前和最近在同一台机器上所做的一样:

npx create-react-app --template typescript .

我从终端得到这个提示

Need to install the following packages: create-react-app Ok to proceed? (y)

我按 y 确认可以继续。 (如果我按 n,进程将终止并出现以下错误:npm ERR! canceled。)然后终端显示以下消息

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

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:
https://create-react-app.dev/docs/getting-started/

我运行两个建议的命令来全局卸载 create-react-app。 npm 顺利:


npm uninstall -g create-react-app

up to date, audited 1 package in 179ms

found 0 vulnerabilities

全局纱线卸载结果显示以下消息:

remove create-react-app
yarn global v1.22.17
warning package.json: No license field
[1/2] ????  Removing module create-react-app...
error This module isn't specified in a package.json file.
info Visit https://yarnpkg.com/en/docs/cli/global for documentation about this command.

最后我尝试查找我的机器上是否存在 create-react-app which create-react-app 这导致 create-react-app not found.

我不确定如何解决这个问题。

编辑:Deepthi 和 Sators 提供的解决方案。我必须使用命令清除存储旧版本 create-react-app 的 npx 缓存:

npx clear-npx-cache

【问题讨论】:

    标签: reactjs typescript yarnpkg npx


    【解决方案1】:

    对于遇到这样的事情: " 您正在运行 create-react-app 4.0.3,它落后于最新版本 (5.0.0)。"

    解决方案是:

    :> npx clear-npx-cache

    然后执行: :> npx create-react-app your-app

    【讨论】:

    • 谢谢!我尝试了从清除 npm 缓存到卸载和重新安装节点的所有方法,最后这个解决方案修复了它:)
    • 谢谢!该命令解决了我的问题。
    【解决方案2】:

    你可以尝试通过运行找到安装的版本:

    npm ls -g create-react-app
    

    您可能还需要考虑阅读 this post 以使用以下方法删除/清除 npx 缓存:

    npx clear-npx-cache
    

    最后,另一种选择是通过运行以下命令来确保您使用的是最新版本的 create-react-app:

    npx create-react-app@latest --template typescript .
    

    【讨论】:

    • 清除 npx 缓存对我有用。我再次进入快乐的黑客领域,非常感谢!!!
    • 您好,我遇到了类似的问题,但使用yarn create react-app 我清理了所有缓存,并删除了所有全局安装,但问题仍然存在。知道为什么会发生这种情况吗? - 顺便说一句,我不能使用 v5.0.0,因为我的服务器在节点 12 上
    • 你可以试试yarn create react-app@latest
    【解决方案3】:

    显然那个版本有问题,我只是有同样的问题,但是命令

    npx clear-npx-cache
    

    它成功了,然后我刚刚运行了

    npx create-react-app proyect-name
    

    而且它有效!

    我认为这与上面的答案相同,但是,你去吧。

    【讨论】:

      【解决方案4】:

      这里的问题是 npx create-react-app 正在尝试从旧版本 (4.0.3) 安装软件包,而最新版本是 (5.0.0)。

      您可以使用以下命令简单地清除 npx 缓存:

      npx clear-npx-cache

      然后尝试使用

      再次创建一个反应应用程序

      npx create-react-app Your_project_name

      或者

      您可以将 npx 与 @latest 一起使用,以确保您正在运行 create-react-app 以及最新版本:

      npx create-react-app@latest Your_project_name

      或者

      您可以使用以下命令在本地工作目录中安装最新的 react 应用模块:

      npm install create-react-app@latest

      (这将在安装react应用时依赖的工作目录中除了package.json和package-lock.json之外创建react模块,因此您可以在完成下一步后将它们删除)

      然后:

      npx create-react-app Your_project_name

      【讨论】:

      • 谢谢@sanad-khamash。 npx create-react-app@latest 为我工作以确保我正在运行 create-react-app 最新版本。
      • @Shraddha 先生,非常欢迎您。
      【解决方案5】:

      运行 ---> npx clear-npx-cache

       ----> npx create-react-app your-app
      

      【讨论】:

        【解决方案6】:

        运行npx clear-npx-cache

        为什么?

        您之前已经尝试使用 create-react-app 创建一个 React 项目。

        所以在 npx 缓存中有一个旧版本的 create-react-app。 /user/.npm/_npx

        npm uninstall -g create-react-app 不适用于这种情况。

        如果你运行npx clear-npx-cache,它将删除目录/user/.npm/_npx中的所有缓存

        现在您可以使用 npx create-react-app my_app 创建 React 应用程序

        【讨论】:

          【解决方案7】:

          您正在运行create-react-app 4.0.3,它落后于最新版本 (5.0.0)。

          我们不再支持全局安装 Create React App。

          请使用以下命令之一删除所有全局安装:

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

          可在此处找到有关创建新应用的最新说明: https://create-react-app.dev/docs/getting-started/

          是的,它与上面一样。

          运行以下两个选项中的一些:

          npm uninstall -g create-react-app
          

          yarn global remove create-react-app
          

          最后用 npx 命令 create-react-app 再试一次

          就我而言,我使用来自npm unistall 的那个,如果我开始创建React 项目,最后在那里再次运行命令npx create-react-app

          【讨论】:

            【解决方案8】:

            如果您已尝试上述所有方法但均未成功。

            运行:

            npm audit fix --force
            

            然后:

            npx create-react-app <app
            

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 2020-04-14
              • 1970-01-01
              • 1970-01-01
              • 2021-09-07
              • 2021-03-05
              • 2020-08-11
              • 2018-11-05
              相关资源
              最近更新 更多