[JS每N日N练] Mac笔记本上使用pig-ui项目,node-sass安装报错

问题定位

报错啦

今天在Mac笔记本上安装pig-ui框架的时候,报错啦

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仓库npm config get registry,已经配置成了阿里镜像了;而且尝试了很多次安装,都失败了,排除网络原因造成的。
  • 库与node版本冲突,这个是之前安装库的时候遇到的一种情况。查看上面的日志,可以看到是安装node-sass报错啦,网上搜索node安装node-sass出错,可以查看很多资料,原因也很多,还好看到一篇文章1,报错跟我的报错一致的。
  • 文章1中说,node和node-sass版本不一致导致的,其对应关系如下图:
    在这里插入图片描述
  • 查看pig-ui配置文件中使用的node-sass版本是4.14.1,对应上图需要使用Node14,而我本机使用的是Node16,参考网上说明,对于开源项目,应该降低Node版本,而不是升级node-sass,避免该开源项目中其他库或者代码因为node-sass版本不匹配导致错误。

什么是Sass?
Sass是一种预处理器脚本语言,可以解释或编译成层叠样式表(CSS)。

解决问题

卸载现在的Node版本

sudo rm -rf /usr/local/{bin/{node,npm},lib/node_modules/npm,lib/node,share/man/*/node.*}

安装node14

  • 访问官网:https://nodejs.org/,点击``:
    在这里插入图片描述
  • 下载页面中点击Previous Releases:
    在这里插入图片描述
  • 选择Node14最后一个版本14.18.3,点击Download
    在这里插入图片描述- 下载安装包文件node-v14.18.3.pkg
    在这里插入图片描述
  • 然后就是一路下一步就可以了

上述流程中,最终下载地址为:https://nodejs.org/download/release/v14.18.3/node-v14.18.3.pkg
如果遇到的node官网速度太慢可以访问下面的镜像地址:https://npmmirror.com/mirrors/node/v14.18.3/node-v14.18.3.pkg

验证结果

  • 切换到pig-ui项目,删除node_modules目录
  • 然后重新安装依赖npm i
  • 最后运行项目npm run dev,一切正常了

尽量不要npm和cnpm一起使用,会导致各种包冲突,这里建议设置阿里镜像,然后只使用npm。

参考资料

  • 科技造梦想,逐梦创未来:夜猫逐梦技术交流裙/953949723
    逐梦中原技术交流QQ群

  1. node-sass与node版本不匹配问题解决方法
    https://www.codenong.com/cs122036023/ ↩︎ ↩︎

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

夜猫逐梦

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值