我试图在Ubuntu 18.04中使用命令sudo npm install -g gatsby-cli
安装gatsby-cli。
我的Node版本是16.14.2和npm 8.5.0。但是盖茨比安装不识别这些版本。它一直说我的当前版本是Node 8.5.0和npm 3.5.2,导致安装错误,你可以在下面的终端输出中看到。
我能做些什么来解决这个问题?
WARN engine gatsby-cli@4.13.0: wanted: {"node":">=14.15.0"} (current: {"node":"8.10.0","npm":"3.5.2"})
loadDep:yurnalist → addNa
WARN engine execa@5.1.1: wanted: {"node":">=10"} (current: {"node":"8.10.0","npm":"3.5.2"})
loadDep:yurnalist → addNa
loadDep:yurnalist → resol
WARN engine gatsby-telemetry@3.13.0: wanted: {"node":">=14.15.0"} (current: {"node":"8.10.0","npm":"3.5.2"})
WARN engine boxen@5.1.2: wanted: {"node":">=10"} (current: {"node":"8.10.0","npm":"3.5.2"})
WARN engine gatsby-core-utils@3.13.0: wanted: {"node":">=14.15.0"} (current: {"node":"8.10.0","npm":"3.5.2"})
WARN engine semver@7.3.7: wanted: {"node":">=10"} (current: {"node":"8.10.0","npm":"3.5.2"})
WARN engine hosted-git-info@3.0.8: wanted: {"node":">=10"} (current: {"node":"8.10.0","npm":"3.5.2"})
npm WARN deprecated uuid@3.4.0: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
loadDep:is-wsl → 304
loadDep:wrap-ansi → resol
WARN engine type-fest@0.20.2: wanted: {"node":">=10"} (current: {"node":"8.10.0","npm":"3.5.2"})
loadDep:typedarray-to-buf
loadDep:strip-final-newli
loadDep:mimic-fn → addNam
loadDep:tmp → request
npm ERR! Linux 4.15.0-176-generic
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "install" "-g" "gatsby-cli"
npm ERR! node v8.10.0
npm ERR! npm v3.5.2
npm ERR! code EMISSINGARG
npm ERR! typeerror Error: Missing required argument #1
npm ERR! typeerror at andLogAndFinish (/usr/share/npm/lib/fetch-package-metadata.js:31:3)
npm ERR! typeerror at fetchPackageMetadata (/usr/share/npm/lib/fetch-package-metadata.js:51:22)
npm ERR! typeerror at resolveWithNewModule (/usr/share/npm/lib/install/deps.js:456:12)
npm ERR! typeerror at /usr/share/npm/lib/install/deps.js:457:7
npm ERR! typeerror at /usr/share/npm/node_modules/iferr/index.js:13:50
npm ERR! typeerror at /usr/share/npm/lib/fetch-package-metadata.js:37:12
npm ERR! typeerror at addRequestedAndFinish (/usr/share/npm/lib/fetch-package-metadata.js:82:5)
npm ERR! typeerror at returnAndAddMetadata (/usr/share/npm/lib/fetch-package-metadata.js:117:7)
npm ERR! typeerror at pickVersionFromRegistryDocument (/usr/share/npm/lib/fetch-package-metadata.js:134:20)
npm ERR! typeerror at /usr/share/npm/node_modules/iferr/index.js:13:50
npm ERR! typeerror This is an error with npm itself. Please report this error at:
npm ERR! typeerror <http://github.com/npm/npm/issues>
WARN engine tmp@0.2.1: wanted: {"node":">=8.17.0"} (current: {"node":"8.10.0","npm":"3.5.2"})
WARN engine import-from@4.0.0: wanted: {"node":">=12.2"} (current: {"node":"8.10.0","npm":"3.5.2"})
WARN engine got@11.8.3: wanted: {"node":">=10.19.0"} (current: {"node":"8.10.0","npm":"3.5.2"})
npm ERR! Please include the following file with any support request:
npm ERR! /home/development/blog-gatsby/npm-debug.log
我设法修复了上面的错误。问题是,即使使用yarn
或npm
而不使用sudo
,安装过程也会以root用户安装的Node版本(8.10.0)进行。
为了解决这个问题,我以root用户身份登录,并执行:
curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash -
sudo apt-get install -y nodejs
之后,安装了命令gatsby,命令sudo npm install -g gatsby-cli
没有问题。
希望对大家有所帮助。