macOS下使用npm install 报错 node-sass npm ERR! command failed command sh -c node-gyp rebuild

macOS下使用npm install 报错 node-sass npm ERR! command failed command sh -c node-gyp rebuild

最近跑npm install总是提示这样的错误,使用淘宝镜像也是如此,参考如下

npm ERR! code 1
npm ERR! path /Users/memory/Desktop/ui/node_modules/node-sass
npm ERR! command failed
npm ERR! command sh -c node-gyp rebuild
npm ERR! CXX(target) Release/obj.target/libsass/src/libsass/src/ast.o
npm ERR!   CXX(target) Release/obj.target/libsass/src/libsass/src/ast_fwd_decl.o
npm ERR!   CXX(target) Release/obj.target/libsass/src/libsass/src/backtrace.o
npm ERR!   CXX(target) Release/obj.target/libsass/src/libsass/src/base64vlq.o
npm ERR!   CXX(target) Release/obj.target/libsass/src/libsass/src/bind.o
npm ERR!   CC(target) Release/obj.target/libsass/src/libsass/src/cencode.o
npm ERR!   CXX(target) Release/obj.target/libsass/src/libsass/src/check_nesting.o
npm ERR!   CXX(target) Release/obj.target/libsass/src/libsass/src/color_maps.o
npm ERR!   CXX(target) Release/obj.target/libsass/src/libsass/src/constants.o
npm ERR!   CXX(target) Release/obj.target/libsass/src/libsass/src/context.o
npm ERR!   CXX(target) Release/obj.target/libsass/src/libsass/src/cssize.o
npm ERR!   CXX(target) Release/obj.target/libsass/src/libsass/src/emitter.o
npm ERR!   CXX(target) Release/obj.target/libsass/src/libsass/src/environment.o
npm ERR!   CXX(target) Release/obj.target/libsass/src/libsass/src/error_handling.o
npm ERR!   CXX(target) Release/obj.target/libsass/src/libsass/src/eval.o
npm ERR!   CXX(target) Release/obj.target/libsass/src/libsass/src/expand.o
npm ERR!   CXX(target) Release/obj.target/libsass/src/libsass/src/extend.o
npm ERR!   CXX(target) Release/obj.target/libsass/src/libsass/src/file.o
npm ERR!   CXX(target) Release/obj.target/libsass/src/libsass/src/functions.o
npm ERR!   CXX(target) Release/obj.target/libsass/src/libsass/src/inspect.o
npm ERR!   CXX(target) Release/obj.target/libsass/src/libsass/src/json.o
npm ERR!   CXX(target) Release/obj.target/libsass/src/libsass/src/lexer.o
npm ERR!   CXX(target) Release/obj.target/libsass/src/libsass/src/listize.o
npm ERR!   CXX(target) Release/obj.target/libsass/src/libsass/src/memory/SharedPtr.o
npm ERR!   CXX(target) Release/obj.target/libsass/src/libsass/src/node.o
npm ERR!   CXX(target) Release/obj.target/libsass/src/libsass/src/operators.o

解决思路大概如下:
1.检查xcode-select是不是安装正确
2.全局安装node-sass,命令sudo npm install -g node-sass
3.全局安装node-gyp,命令sudo npm install node-gyp@latest
4.全局安装npm-lifecycle,命令sudo npm install npm-lifecycle