mac电脑node-sass安装失败问题

背景:

libtool: unrecognized option `-static'
libtool: Try `libtool --help' for more information.
make: *** [Release/sass.a] Error 1
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/tomcat/project/spring-cloud-codegen-ui/node_modules/node-gyp/lib/build.js:258:23)
gyp ERR! stack     at emitTwo (events.js:106:13)
gyp ERR! stack     at ChildProcess.emit (events.js:194:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:215:12)
gyp ERR! System Darwin 15.6.0
gyp ERR! command "/usr/local/Cellar/node/5.8.0/bin/node" "/usr/local/tomcat/project/spring-cloud-codegen-ui/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd /usr/local/tomcat/project/spring-cloud-codegen-ui/node_modules/node-sass
gyp ERR! node -v v7.8.0
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok 
Build failed with error code: 1
npm ERR! Darwin 15.6.0
npm ERR! argv "/usr/local/Cellar/node/5.8.0/bin/node" "/usr/local/bin/npm" "install"
npm ERR! node v7.8.0
npm ERR! npm  v4.2.0
npm ERR! code ELIFECYCLE
npm ERR! errno 1

npm ERR! [email protected] postinstall: `node scripts/build.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] postinstall script 'node scripts/build.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the node-sass package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node scripts/build.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs node-sass
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls node-sass
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /var/root/.npm/_logs/2018-01-03T01_21_29_137Z-debug.log

报错信息如上

错误原因:

1、node版本和node-sass版本匹配
2、commands line tools工具版本和电脑系统版本不一致

解决方案:

步骤一:

首先查看node版本和node-sass版本是否相匹配
mac电脑node-sass安装失败问题_第1张图片
确认版本匹配后继续

步骤二:

打开终端

xcode-select --install

会提示安装xcode-select工具,傻瓜式下一步就好,安装成功后就可以正常安装node-sass了!
1、但是有些同学电脑上可能会提示网络连接失败,莫慌,继续下一步
2、https://developer.apple.com/download/more/ 瞄准这个网站,如图搜索框搜索“commands line tools”,不要安装beta版
mac电脑node-sass安装失败问题_第2张图片mac电脑node-sass安装失败问题_第3张图片
3、下载安装好大功告成,node-sass就可以正常安装

总结:

有很多朋友就会问,我安装node-sass跟commands line tools有什么关系?mac电脑node-sass安装失败问题_第4张图片
我讲讲个人理解,大家仔细看看报错信息,gyp ERR和No Xcode,其实node-sass的安装是依赖于node-gyp(用来支持和扩展一些C++底层语言)来解析编译的,同时node-gyp要靠mac终端的commands line tools工具来支持,所以你的commands line tools版本有误最终就会导致node-sass安装失败。
其实我本机突然安装失败就是因为我不小心升级了mac系统版本,这是个大坑。

你可能感兴趣的:(前端开发技巧)