通过yarn install装置依赖包node-sass时总是报错,具体的谬误起因为Command failed。应该如何解决这个问题呢?

报错信息

D:\testspace\test\node_modules\node-sass: Command failed.Exit code: 1Command: node scripts/build.jsArguments:Directory: D:\testspace\test\node_modules\node-sassOutput:Building: C:\Program Files\nodejs\node.exe D:\testspace\test\node_modules\node-gyp\bin\node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=gyp info it worked if it ends with okgyp verb cli [gyp verb cli   'C:\\Program Files\\nodejs\\node.exe',gyp verb cli   'D:\\testspace\\test\\node_modules\\node-gyp\\bin\\node-gyp.js',gyp verb cli   'rebuild',gyp verb cli   '--verbose',gyp verb cli   '--libsass_ext=',gyp verb cli   '--libsass_cflags=',gyp verb cli   '--libsass_ldflags=',gyp verb cli   '--libsass_library='gyp verb cli ]gyp info using node-gyp@3.8.0gyp info using node@16.14.2 | win32 | x64gyp verb command rebuild []gyp verb command clean []gyp verb clean removing "build" directorygyp verb command configure []gyp verb download using dist-url https://npm.taobao.org/distgyp verb check python checking for Python executable "python2" in the PATHgyp verb `which` failed Error: not found: python2gyp verb `which` failed     at getNotFoundError (D:\testspace\test\node_modules\which\which.js:13:12)gyp verb `which` failed     at F (D:\testspace\test\node_modules\which\which.js:68:19)gyp verb `which` failed     at E (D:\testspace\test\node_modules\which\which.js:80:29)gyp verb `which` failed     at D:\testspace\test\node_modules\which\which.js:89:16gyp verb `which` failed     at D:\testspace\test\node_modules\isexe\index.js:42:5gyp verb `which` failed     at D:\testspace\test\node_modules\isexe\windows.js:36:5gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:198:21)gyp verb `which` failed  python2 Error: not found: python2gyp verb `which` failed     at getNotFoundError (D:\testspace\test\node_modules\which\which.js:13:12)gyp verb `which` failed     at F (D:\testspace\test\node_modules\which\which.js:68:19)gyp verb `which` failed     at E (D:\testspace\test\node_modules\which\which.js:80:29)gyp verb `which` failed     at D:\testspace\test\node_modules\which\which.js:89:16gyp verb `which` failed     at D:\testspace\test\node_modules\isexe\index.js:42:5gyp verb `which` failed     at D:\testspace\test\node_modules\isexe\windows.js:36:5gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:198:21) {gyp verb `which` failed   code: 'ENOENT'gyp verb `which` failed }gyp verb check python checking for Python executable "python" in the PATHgyp verb `which` succeeded python C:\Users\PC\AppData\Local\Programs\Python\Python36\python.EXEgyp ERR! configure errorgyp ERR! stack Error: Command failed: C:\Users\PC\AppData\Local\Programs\Python\Python36\python.EXE -c import sys; print "%s.%s.%s" % sys.version_info[:3];gyp ERR! stack   File "<string>", line 1gyp ERR! stack     import sys; print "%s.%s.%s" % sys.version_info[:3];gyp ERR! stack                                ^gyp ERR! stack SyntaxError: invalid syntaxgyp ERR! stackgyp ERR! stack     at ChildProcess.exithandler (node:child_process:399:12)gyp ERR! stack     at ChildProcess.emit (node:events:526:28)gyp ERR! stack     at maybeClose (node:internal/child_process:1092:16)gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:302:5)gyp ERR! System Windows_NT 10.0.22621gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "D:\\testspace\\test\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="gyp ERR! cwd D:\testspace\test\node_modules\node-sassgyp ERR! node -v v16.14.2gyp ERR! node-gyp -v v3.8.0gyp ERR! not okBuild failed with error code: 1info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

谬误起因

我的以后环境是node v16.14.2,我装置的版本是node-sass v4.14.1。报错的根本原因是nodenode-sass的版本不匹配。

指引

以下是node-sass反对最低到最高版本的疾速指引:

NodeJSSupported node-sass versionNode Module
Node 198.0+111
Node 188.0+108
Node 177.0+, <8.0102
Node 166.0+93
Node 155.0+, <7.088
Node 144.14+83
Node 134.13+, <5.079
Node 124.12+, <8.072
Node 114.10+, <5.067
Node 104.9+, <6.064
Node 84.5.3+, <5.057
Node <8<5.0<57

参考

node-sass - npm

欢送关注我的微信公众号:乘风破浪的Coder