如何摆脱`节点“13.0.0-nightly20190802452b393c1f”`以便我能够使用`create-react-app`工具创建react应用程序?

IT技术 reactjs visual-studio-code create-react-app npm-scripts
2021-05-05 08:43:08

我正在尝试create-react-appubuntu 18.04终端中使用 npx 的命令创建一个react应用程序我已经Node v12.8.0安装了。当我npx create-react-app .在我的应用程序目录中运行命令时,我希望生成 react 应用程序样板文件夹和文件,因为我的机器上有最新版本的Node v12.8.0npm v6.10.2。相反,我得到以下输出...

npx: installed 91 in 5.725s

Creating a new React app in /home/<my-PC>/Documents/todo-app.

warning You are using Node "13.0.0-nightly20190802452b393c1f" which is not supported and may encounter bugs or unexpected behavior. Yarn supports the following semver range: "^4.8.0 || ^5.7.0 || ^6.2.2 || >=8.0.0"
Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts...

yarn add v1.17.3
warning You are using Node "13.0.0-nightly20190802452b393c1f" which is not supported and may encounter bugs or unexpected behavior. Yarn supports the following semver range: "^4.8.0 || ^5.7.0 || ^6.2.2 || >=8.0.0"
[1/4] Resolving packages...
[2/4] Fetching packages...
error @babel/core@7.5.5: The engine "node" is incompatible with this module. Expected version ">=6.9.0". Got "13.0.0-nightly20190802452b393c1f"
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 --cwd /home/<my-PC>/Documents/todo-app has failed.

Deleting generated file... package.json
Deleting generated file... yarn.lock
Deleting todo-app/ from /home/<my-PC>/Documents
Done.

因此,它最终会在创建后立即删除生成的应用程序文件夹。我认为它受到上述Node "13.0.0-nightly20190802452b393c1f"指定的影响我试图找到它,但在我的机器上找不到它。在终端上,当我运行时,node -v我得到了v12.8.0用于 nodejs的版本卡在这里了...

4个回答
  1. 从 ubuntu 软件管理器卸载 node js。

  2. 然后使用以下命令安装 node js:

    sudo apt-get update
    sudo apt-get install nodejs
    

如果您安装了多个版本的 nodejs,您可以使用以下-p选项直接定位它们

npx -p node@12 

对于 create-react-app

npx -p node@12 create-react-app billion-dollar-project

我有同样的错误并强制 create-react-app 使用 npm 而不是 yarn 修复了它。尝试npx create-react-app appname --use-npm

只需运行以下命令:

create-react-app app-name --use-npm

这明确告诉 react 使用 npm 而不是 yarn。