MAC 安装 node-sass4.12.0报错AttributeError: ‘module‘ object has no attribute ‘sha1‘

每次遇到有工程使用node-sass的都经常因为环境出问题,尤其是一些老项目,处理起来比较按麻烦。

File "/xxx/node_modules/node-gyp/gyp/pylib/gyp/xcodeproj_file.py", line 152, in <module>
    _new_sha1 = hashlib.sha1
AttributeError: 'module' object has no attribute 'sha1'
gyp ERR! configure error 
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onCpExit (/xxx/node_modules/node-gyp/lib/configure.js:345:16)
gyp ERR! stack     at ChildProcess.emit (events.js:314:20)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:276:12)
gyp ERR! System Darwin 24.0.0
gyp ERR! command "/xxx/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd /xxx/node_modules/node-sass
gyp ERR! node -v v12.22.12
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok 

看报错,是python版本兼容问题导致。看了下系统python版本是2.7.18。也不纠结了,直接改下python脚本。

直接找到出错文件:/node_modules/node-gyp/gyp/pylib/gyp/xcodeproj_file.py

152行:

原始代码:_new_sha1 = hashlib.sha1

改成:_new_sha1 = hashlib.new

425行:

原始代码:seed_hash = _new_sha1()

改成:seed_hash = _new_sha1('sha1')

依赖安装编译成功。

猜你喜欢

转载自blog.csdn.net/weixin_53725481/article/details/142500298