使用create-react-app创建新的React应用时遇到问题

时间:2020-10-26 02:17:26

标签: reactjs npm create-react-app npx

我正在尝试创建一个新的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.

我已经尝试了一段时间,但无法正常工作。

2 个答案:

答案 0 :(得分:2)

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

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

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

  3. sudo n稳定升级//到当前稳定版本

答案 1 :(得分:1)

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

问题:

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模块仅与101214的{​​{1}}版本兼容,并且您正在使用node

解决方案

要解决此错误,您需要升级或降级当前的13.12.0版本。

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

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

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

node

对于CURL,运行以下命令:

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

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

一旦下载成功,将重新启动终端,否则将无法找到终端。如果失败,则可能需要重置计算机。

如果您已安装 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
相关问题