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
, npm cache clean --force
清除一下缓存,否则rebuild的时候npm很可能用了本地缓存的node-sass文件(吃亏了md)
清除缓存后npm rebuild node-sass
执行成功 控制台提示下载的是darwin-x64-72/binding.node
然后切回之前项目要求的node 14
版本 编译执行,成功运行
done