首页 > 解决方案 > 使用 create-react-app 创建新的 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.

我一直试图弄清楚它有一段时间了,但无法让它发挥作用。

标签: reactjsnpmcreate-react-appnpx

解决方案


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

问题:

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版本兼容。101214node13.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

推荐阅读