uniapp项目在HBuilderX中运行编译时node-sass版本环境问题记录

Node Sass could not find a binding for your current environment: 问题

接手项目时要求环境为node 14,但是在运行编译的时候控制台报错

Module Error (from ./node_modules/sass-loader/dist/cjs.js):
Missing binding /Users/leon/Documents/projects/zzz/uni-mobile-protection/node_modules/node-sass/vendor/darwin-x64-72/binding.node
Node Sass could not find a binding for your current environment: OS X 64-bit with Node.js 12.x
Found bindings for the following environments:
   - Windows 64-bit with Node.js 14.x
   - OS X 64-bit with Node.js 14.x

于是执行npm rebuild node-sass,理论上会重新pull node-sass中缺少的文件 即为darwin-x64-72/binding.node
但是重新运行编译还是报相同的错误
仔细查看npm rebuild node-sass的结果

leon@leondeMac-mini uni-mobile-protectionx % npm rebuild node-sass

> node-sass@5.0.0 install /Users/leon/Documents/projects/zzz/uni-mobile-protectionx/node_modules/node-sass
> node scripts/install.js

node-sass build Binary found at /Users/leon/Documents/projects/zzz/uni-mobile-protectionx/node_modules/node-sass/vendor/darwin-x64-83/binding.node

> node-sass@5.0.0 postinstall /Users/leon/Documents/projects/zzz/uni-mobile-protectionx/node_modules/node-sass
> node scripts/build.js

Binary found at /Users/leon/Documents/projects/zzz/uni-mobile-protectionx/node_modules/node-sass/vendor/darwin-x64-83/binding.node
Testing binary
Binary is fine
node-sass@5.0.0 /Users/leon/Documents/projects/zzz/uni-mobile-protectionx/node_modules/node-sass

npm自动安装了darwin-x64-83/binding.node,因为当前运行的node环境是node14
报错提示缺少darwin-x64-72/binding.node,根据提示和node-sass文档可知72对应的node版本为node12
所以用nvm切换node版本为node 12,\color{#FF0000}{重点:防止万一执行一下} npm cache clean --force清除一下缓存,否则rebuild的时候npm很可能用了本地缓存的node-sass文件(吃亏了md)
清除缓存后npm rebuild node-sass 执行成功 控制台提示下载的是darwin-x64-72/binding.node
然后切回之前项目要求的node 14版本 编译执行,成功运行
done

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容