【发布时间】: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 stable和npm install -g node最终给了我同样的错误!!! -
你应该先卸载
npm和所有个Nodejs实例,然后全局安装node。您也不需要单独安装npm,因为它随node软件包提供。
标签: node.js reactjs ubuntu npm