node-sass与node版本映射问题
更新时间:2026年05月12日 10:30:42 作者:白鸽呀
文章提到因Node.js版本不匹配导致node-sass安装出现问题,需将node版本升级到6.x才能安装成功,这是根据个人经验总结出来的解决方法,供开发者们在遇到类似问题时提供参考
背景
版本不匹配,比如在node16上面安装node-sass 4.x
就可能会报以下错误
npm ERR! & npm ERR! 2 warnings generated. npm ERR! In file included from ../src/binding.cpp:1: npm ERR! In file included from ../../nan/nan.h:58: npm ERR! In file included from /Users/chris/.node-gyp/16.13.1/include/node/node.h:63: npm ERR! In file included from /Users/chris/.node-gyp/16.13.1/include/node/v8.h:30: npm ERR! /Users/chris/.node-gyp/16.13.1/include/node/v8-internal.h:492:38: error: no template named 'remove_cv_t' in namespace 'std'; did you mean 'remove_cv'? npm ERR! !std::is_same<Data, std::remove_cv_t<T>>::value>::Perform(data); npm ERR! ~~~~~^~~~~~~~~~~ npm ERR! remove_cv npm ERR! /Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/usr/include/c++/v1/type_traits:710:50: note: 'remove_cv' declared here npm ERR! template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_cv npm ERR! ^ npm ERR! 1 error generated. npm ERR! make: *** [Release/obj.target/binding/src/binding.o] Error 1 npm ERR! gyp ERR! build error npm ERR! gyp ERR! stack Error: `make` failed with exit code: 2 npm ERR! gyp ERR! stack at ChildProcess.onExit (/Users/chris/Java/datax-web-ui/node_modules/node-gyp/lib/build.js:262:23) npm ERR! gyp ERR! stack at ChildProcess.emit (node:events:390:28) npm ERR! gyp ERR! stack at Process.ChildProcess._handle.onexit (node:internal/child_process:290:12) npm ERR! gyp ERR! System Darwin 20.6.0 npm ERR! gyp ERR! command "/usr/local/bin/node" "/Users/chris/Java/datax-web-ui/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library=" npm ERR! gyp ERR! cwd /Users/chris/Java/datax-web-ui/node_modules/node-sass npm ERR! gyp ERR! node -v v16.13.1 npm ERR! gyp ERR! node-gyp -v v3.8.0 npm ERR! gyp ERR! not ok npm ERR! Build failed with error code: 1 npm ERR! A complete log of this run can be found in: npm ERR! /Users/chris/.npm/_logs/2021-12-20T01_39_51_471Z-debug.log
项目中 node-sass 版本为4.x
本地node为14,但是服务器安装的node版本是 16,要求node-sass版本为 6.x,更换node即可。

总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。
相关文章
node.js连接mongoDB数据库 快速搭建自己的web服务
这篇文章主要为大家详细介绍了node.js连接mongoDB数据库,如何快速搭建自己的web服务,感兴趣的小伙伴们可以参考一下2016-04-04
基于node.js依赖express解析post请求四种数据格式
本篇文章主要介绍了node.js依赖express解析post请求四种数据格式,主要是www-form-urlencoded,form-data,application/json,text/xml,有兴趣的可以了解一下。2017-02-02


最新评论