繁体   English   中英

create-react-app 说“Create React App 需要 Node 14 或更高版本。” 修复节点给出“npm 不支持 Node.js v10.19.0”

[英]create-react-app says "Create React App requires Node 14 or higher." Fixing node gives "npm does not support Node.js v10.19.0"

我试图创建一个 React 应用程序,但得到了关注

$ npx create-react-app react-demo
npx: installed 67 in 6.045s
You are running Node 10.19.0.
Create React App requires Node 14 or higher. 
Please update your version of Node.

在解决方案中,答案要求运行npm i -g npm@latest ,这会给出另一个错误:

$ sudo npm i -g npm@latest
npm does not support Node.js v10.19.0
You should probably upgrade to a newer version of node as we
can't make any promises that npm will work with this version.
You can find the latest version at https://nodejs.org/
/usr/local/lib/node_modules/npm/lib/npm.js:32
  #unloaded = false
  ^

SyntaxError: Invalid or unexpected token
    at Module._compile (internal/modules/cjs/loader.js:723:23)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at module.exports (/usr/local/lib/node_modules/npm/lib/cli.js:22:15)
    at Object.<anonymous> (/usr/local/lib/node_modules/npm/bin/npm-cli.js:2:25)
    at Module._compile (internal/modules/cjs/loader.js:778:30)

此错误的解决方案要求卸载npm ,这会给出相同的错误:

$ sudo npm uninstall -g npm
npm does not support Node.js v10.19.0
You should probably upgrade to a newer version of node as we
can't make any promises that npm will work with this version.
You can find the latest version at https://nodejs.org/
/usr/local/lib/node_modules/npm/lib/npm.js:32
  #unloaded = false
  ^

SyntaxError: Invalid or unexpected token
    at Module._compile (internal/modules/cjs/loader.js:723:23)
    //..
    at Module._compile (internal/modules/cjs/loader.js:778:30)

上述错误的解决方案要求安装 helper utility n ,这也会给出相同的错误:

$ sudo npm install -g n
npm does not support Node.js v10.19.0
You should probably upgrade to a newer version of node as we
can't make any promises that npm will work with this version.
You can find the latest version at https://nodejs.org/
/usr/local/lib/node_modules/npm/lib/npm.js:32
  #unloaded = false
  ^

SyntaxError: Invalid or unexpected token
    at Module._compile (internal/modules/cjs/loader.js:723:23)
    //..
    at Module._compile (internal/modules/cjs/loader.js:778:30)

我非常困惑这里发生了什么。 我该如何解决?

PS:我对 npm 和节点很陌生。

我的解决方案是使用$ sudo apt update更新 ubuntu 然后使用$ sudo n stable安装最新版本的 nodejs

你需要的是节点管理器,使用npm install -gn在使用$ sudo n stable之前安装

这对我有用

npm cache clean -f 
sudo npm install -g n
sudo n latest 
  • 我也遇到同样的问题试试这个

    1. curl -sL https://deb.nodesource.com/setup_16.x -o nodesource_setup.sh
    2. 使用 nano(或您喜欢的文本编辑器)检查下载脚本的内容: nano nodesource_setup.sh
    3. 当您对脚本可以安全运行感到满意时,退出编辑器,然后使用 sudo 运行脚本: sudo bash nodesource_setup.sh
    4. sudo apt install nodejs
    5. node -v

Hola a todos yo lo resolví siguiendo los siguientes pasos Abrir un terminar y escribir lo siguiente para actualizar el nvm

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

Luego cerrar el terminal y volver abrirlo para que se actualice

一个 continuación instalar node 16.x con:

nvm install 16

利斯托

En ingles, traducido con 谷歌翻译

大家好,我按照以下步骤解决了打开终止并键入以下内容以更新nvm

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

然后关闭终端并重新打开以更新

接下来安装节点 16.x:

 nvm install 16

准备好

我有同样的问题。 按照https://github.com/nodejs/help/wiki/Installation中的说明进行操作,您的安装就可以了。

基本上,您需要下载二进制文件安装,并按照说明仅更改版本。

只需点击此命令npm install node

要使用命令 npx create-react-app my-app 创建一个反应应用程序,需要比当前安装在您的机器上的节点更高版本。 为了解决这个问题,我使用了节点版本管理器(nvm)。 我运行命令:-

  1. sudo apt 更新
  2. curl -o-https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
  3. nvm--版本
  4. 非虚拟机
  5. nvm ls-远程
  6. nvm install [版本号]

示例你可以输入 nvm install v16.13.1 你很好 go: 参考资料:- https://phoenixnap.com/kb/update-node-js-version

  1. 通过运行node -v验证您安装的节点版本是否等于或大于 create-react-app 安装程序抱怨的版本
  2. 如有必要,您可以通过运行npm i -g安装最新的稳定节点版本(在本文发布时,最新的 LTS 版本为 16.13.2,其中包括 npm 8.1.2)
  3. 在要创建 React 应用程序的父文件夹中,运行npm init -y
  4. 仍在父文件夹中时,运行以下命令创建您的 React 应用程序: npx create-react-app yourAppName
  5. 运行cd yourAppName导航到新创建的 React App
  6. 最后,运行npm start并在默认浏览器中查看新的 React 应用程序。

就是这样,祝你好运!

我遇到了类似的问题,这种方法对我有用。

curl -fsSL https://deb.nodesource.com/setup_current.x | sudo -E bash -
sudo apt-get install -y nodejs

有关更多详细信息,请查看此问题https://askubuntu.com/questions/426750/how-can-i-update-my-nodejs-to-the-latest-version

您可以卸载create-react-app并重新安装支持当前节点版本的工作版本,如下所示。 有关更多信息,请参阅此答案

npm uninstall -g create-react-app
npm install -g create-react-app@3.4.1
create-react-app my-app --scripts-version 3.1.1

我认为你必须选择 YARN,因为 NPM 顺序安装包,Yarn 执行并行安装从而获得更好的速度和性能。

  1. 首先安装纱线
 sudo apt remove yarn curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list sudo apt-get update
    sudo apt-get install yarn -y
  1. 然后
yarn create react-app project-name

使用 WSL-1,通过 nvm 安装节点,这至少对我有用。

sudo apt-get remove-y nodejs
rm -rf ~/.nvm

sudo apt-get install nvm
nvm install --lts
nvm use --delete-prefix v18 

我一直在搜索帖子几个小时。

尝试使用 create-react-app 时我有以下内容:

sudo npx create-react-app frontend

create-react-app@5.0.1
Ok to proceed? (y) y
npm WARN deprecated tar@2.2.2: This version of tar is no longer supported, and will not receive security updates. Please upgrade asap.
You are running Node 12.12.0.
Create React App requires Node 14 or higher. 
Please update your version of Node.You are running Node 12.12.0.
    Create React App requires Node 14 or higher. 
    Please update your version of Node

但是,我的节点和 npm 是最新的:

node -v
v19.4.0

npm -v
9.2.0

甚至想出了如何检查是否安装了该版本:

nvm uninstall 12.12.0
N/A version is not installed...

我试过了:

  • 清除缓存 npm 和 npx。
  • 使用“sudo n prune”修剪所有旧版本
  • 直接删除 npx 缓存,“sudo rm -rf ~/.npm/_npx”,正如一些相关帖子中所建议的那样。
  • 此线程上列出的所有其他卸载/重新安装包的组合。

事实证明警告真的不是警告,并且更新 tar 有效:

sudo npm i tar 

我认为应该添加这个,因为在过去几个小时的搜索中我没有看到任何提到这个的东西。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM