【问题标题】:having an issue creating new react app with create-react-app使用 create-react-app 创建新的反应应用程序时遇到问题
【发布时间】:2021-02-08 07:57:14
【问题描述】:

我正在尝试创建一个新的 react 项目,但是当我运行 npx create-react-app tik-tok-clone 时出现以下错误

    Creating a new React app in C:\Users\mwars\Documents\GitHub\TikTok-Clone\tik-tok-clone.

Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts with cra-template...

yarn add v1.22.4
[1/4] Resolving packages...
[2/4] Fetching packages...
error postcss@8.1.3: The engine "node" is incompatible with this module. Expected version "^10 || ^12 || >=14". Got "13.12.0"
error Found incompatible module.
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.

Aborting installation.
  yarnpkg add --exact react react-dom react-scripts cra-template --cwd C:\Users\mwars\Documents\GitHub\TikTok-Clone\tik-tok-clone has failed.

Deleting generated file... package.json
Deleting generated file... yarn.lock
Deleting tik-tok-clone/ from C:\Users\mwars\Documents\GitHub\TikTok-Clone
Done.

我已经尝试了一段时间,但无法让它发挥作用。

【问题讨论】:

  • 在 Stack Overflow 上,不显示文字图片。将文本复制到问题中并设置格式,以便于阅读、复制和搜索。
  • 问题是你的nodeJS版本。它要求版本 ^10、^12 和 >=14。可以运行 node --version 吗?
  • @WillianGaspar 我得到 v13.12.0
  • @WillianGaspar 如何更改我的 nodejs 版本
  • 试试这个:phoenixnap.com/kb/update-node-js-version。但在此之前,试试这个帖子,看看它有帮助:stackoverflow.com/questions/56617209/…

标签: reactjs npm create-react-app npx


【解决方案1】:

运行这些命令后它对我有用。

  1. sudo npm cache clean -f //清除你的 npm 缓存

  2. sudo npm install -g n install n //(这可能需要一段时间)

  3. sudo n stable upgrade //到当前的稳定版本

【讨论】:

    【解决方案2】:

    我正在处理同样的问题,并设法理解并解决了它。我将尝试在下面解释它。

    问题:

    error postcss@8.1.3: The engine "node" is incompatible with this module. Expected version "^10 || ^12 || >=14". Got "13.12.0"
    

    这告诉您create_react_app 模块仅与1012 或大于14node 的版本兼容,并且您正在使用13.12.0

    解决方案

    要修复此错误,您需要升级或降级当前版本的node

    一种方法是使用NVM(节点版本管理器)来管理node的多个版本。

    要使用 Linux 或 Mac 安装它,您可以使用以下任一命令

    对于 Wget,在终端上运行以下命令:

      wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
    

    对于 CURL,运行以下命令:

      curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
    

    您需要将命令中的版本号更改为最新的稳定版本。

    下载成功后重启终端,否则找不到。如果失败,您可能需要重置您的计算机。

    如果您安装了NVM,运行以下内容应该会显示您使用的当前版本。

    nvm --version
    

    然后您可以使用以下命令列出节点的可用版本

    nvm ls-remote
    

    选择一个兼容的版本并像这样安装它

    nvm install 14.15.0
    

    跑步

    node -v 
    

    如果不尝试,应该将此显示为您的当前版本

    nvm use v14.15.0
    

    你现在应该没有问题了

    npx create-react-app tik-tok-clone
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-27
      • 1970-01-01
      • 2020-09-16
      • 2019-11-29
      • 2019-01-10
      • 1970-01-01
      • 2022-10-20
      • 2021-03-27
      相关资源
      最近更新 更多