node-sass 安装失败

笔者用 win 10 系统,在前端开发中遇到 node-sass 安装各种问题,从网上找到解决方法。

用管理员打开 cmd/powershell 

1. 解决 win 缺少编译环境

npm install -g node-gyp
// 用管理员权限打开 powershell 成功
npm install --global --production windows-build-tools

2. 安装 node-sass

npm uninstall node-sass // 如果安装过一次失败,运行;否则不用
npm install node-sass --save-dev

 其他解决方法

SASS_BINARY_SITE=http://npm.taobao.org/mirrors/node-sass yarn

使用 yarn ,而在 yarn 前面加上 SASS_BINARY_SITE=http://npm.taobao.org/mirrors/node-sass ,是让 yarn 去下载二进制文件

PS : 这个方法要在 git-base 控制台下,cmd下会提示 SASS_BINARY_SITE 不是内部或外部命令

下面这个方法类似

yarn config set sass-binary-site https://npm.taobao.org/mirrors/node-sass
npm config set sass-binary-site https://npm.taobao.org/mirrors/node-sass
原文地址:https://www.cnblogs.com/lmaster/p/11784355.html