【问题标题】:create-react-app says "Create React App requires Node 14 or higher." Fixing node gives "npm does not support Node.js v10.19.0"create-react-app 说“创建 React 应用程序需要 Node 14 或更高版本。”修复节点给出“npm 不支持 Node.js v10.19.0”
【发布时间】:2022-01-19 09:39:45
【问题描述】:

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

$ 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.

在解决方案中,this 答案要求运行 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)

Solution 到此错误要求卸载 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)

Solution 到上述错误要求安装帮助实用程序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 和 node 还很陌生。

【问题讨论】:

  • 你必须更新节点。
  • 所有错误都告诉你升级节点。
  • 但是同时执行npm install -g npm stablenpm install -g node 最终给了我同样的错误!!!
  • 你应该先卸载npm所有个Nodejs实例,然后全局安装node。您也不需要单独安装npm,因为它随node 软件包提供。

标签: node.js reactjs ubuntu npm


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

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

    1. sudo apt 更新
    2. 卷曲-o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh |重击
    3. nvm --version
    4. nvm ls
    5. nvm ls-remote
    6. nvm install [version.number]

    例如你可以输入 nvm install v16.13.1 你已准备好出发! 参考资料:- https://phoenixnap.com/kb/update-node-js-version

    【讨论】:

      【解决方案3】:
      • 我也遇到了同样的问题,试试这个

        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

      【讨论】:

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

        就是这样,祝你好运!

        【讨论】:

          猜你喜欢
          • 2017-07-07
          • 1970-01-01
          • 2019-04-16
          • 1970-01-01
          • 2022-08-09
          • 2020-01-21
          • 2017-06-10
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多