node-sass 安装失败 Command failed 报错

youtiao66youtiao66 -
node-sass 安装失败 Command failed 报错

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

报错信息
D:\testspace\test\node_modules\node-sass: Command failed.
Exit code: 1
Command: node scripts/build.js
Arguments:
Directory: D:\testspace\test\node_modules\node-sass
Output:
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 ok
gyp 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.0
gyp info using node@16.14.2 | win32 | x64
gyp verb command rebuild []
gyp verb command clean []
gyp verb clean removing "build" directory
gyp verb command configure []
gyp verb download using dist-url https://npm.taobao.org/dist
gyp verb check python checking for Python executable "python2" in the PATH
gyp verb `which` failed Error: not found: python2
gyp 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:16
gyp verb `which` failed     at D:\testspace\test\node_modules\isexe\index.js:42:5
gyp verb `which` failed     at D:\testspace\test\node_modules\isexe\windows.js:36:5
gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:198:21)
gyp verb `which` failed  python2 Error: not found: python2
gyp 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:16
gyp verb `which` failed     at D:\testspace\test\node_modules\isexe\index.js:42:5
gyp verb `which` failed     at D:\testspace\test\node_modules\isexe\windows.js:36:5
gyp 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 PATH
gyp verb `which` succeeded python C:\Users\PC\AppData\Local\Programs\Python\Python36\python.EXE
gyp ERR! configure error
gyp 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 1
gyp ERR! stack     import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack                                ^
gyp ERR! stack SyntaxError: invalid syntax
gyp ERR! stack
gyp 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.22621
gyp 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-sass
gyp ERR! node -v v16.14.2
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
Build failed with error code: 1
info 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 ModuleNode 198.0+111Node 188.0+108Node 177.0+, <8.0102Node 166.0+93Node 155.0+, <7.088Node 144.14+83Node 134.13+, <5.079Node 124.12+, <8.072Node 114.10+, <5.067Node 104.9+, <6.064Node 84.5.3+, <5.057Node <8<5.0<57参考node-sass - npm

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

特别申明:本文内容来源网络,版权归原作者所有,如有侵权请立即与我们联系(cy198701067573@163.com),我们将及时处理。

Tags 标签

前端node.js

扩展阅读

加个好友,技术交流

1628738909466805.jpg