Nodejs node-gyp运行错误
-
现象
控制台错误信息:
npm ERR! path D:\WorkSpace\sc-new-ui\node_modules\node-sass
npm ERR! command failed
npm ERR! command C:\Windows\system32\cmd.exe /d /s /c node-gyp rebuild
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using node-gyp@3.8.0
npm ERR! gyp info using node@16.10.0 | win32 | x64
npm ERR! gyp ERR! configure error
npm ERR! gyp ERR! stack Error: Command failed: C:\Python39\python.EXE -c import sys; print “%s.%s.%s” % sys.version_info[:3];
npm ERR! gyp ERR! stack File “”, line 1
npm ERR! gyp ERR! stack import sys; print “%s.%s.%s” % sys.version_info[:3];
npm ERR! gyp ERR! stack ^
npm ERR! gyp ERR! stack SyntaxError: invalid syntax
npm ERR! gyp ERR! stack
npm ERR! gyp ERR! stack at ChildProcess.exithandler (node:child_process:397:12)
npm ERR! gyp ERR! stack at ChildProcess.emit (node:events:390:28)
npm ERR! gyp ERR! stack at maybeClose (node:internal/child_process:1064:16)
npm ERR! gyp ERR! stack at Socket. (node:internal/child_process:450:11)
npm ERR! gyp ERR! stack at Socket.emit (node:events:390:28)
npm ERR! gyp ERR! stack at Pipe. (node:net:672:12)
npm ERR! gyp ERR! System Windows_NT 10.0.19041
npm ERR! gyp ERR! command “C:\nodejs\node.exe” “D:\WorkSpace\sc-new-ui\node_modules\node-gyp\bin\node-gyp.js” “rebuild”
npm ERR! gyp ERR! cwd D:\WorkSpace\sc-new-ui\node_modules\node-sass
npm ERR! gyp ERR! node -v v16.10.0
npm ERR! gyp ERR! node-gyp -v v3.8.0
npm ERR! gyp ERR! not ok
运行截图
-
解决
思路
将运行环境python版本由3.9.7降到2.7.x
实践
卸载最新python3.9.x
安装python2.7.x
重新安装node-sass
重新安装node-gyp -
分析
本人下载最新的nodejs(v16.10.0),内部插件node-gyp的版本是8.2.0;导致该问题的根本原因是因为node-gyp不支持默认最新的python,导致在编译的时候因获取python版本异常,最后编译终止!
关键信息截图
报错命令在python2.7.18下运行成功截图
初始版本截图:
降级版本截图:
运行成功截图
-
总结
如果还是有问题,直接降级nodejs版本吧!