blog icon indicating copy to clipboard operation
blog copied to clipboard

node-sass安装失败解决方法汇总

Open yangchch6 opened this issue 6 years ago • 3 comments

场景一:windows环境下,node版本为v8.11.3时,全局安装bee-tools,报错:

1、全局安装bee-tools时,报错信息:

> Binary has a problem: Error: The module '\\?\D:\MyDownloads\Download\win32-x64-46_binding.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 51. This version of Node.js requires
NODE_MODULE_VERSION 57. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).

2、解决方案:

  • node版本降低到v7.0.0,重新安装,成功
>node-sass build Binary found at D:\MyDownloads\Download\win32-x64-46_binding.node

> [email protected] postinstall C:\Users\Administrator\AppData\Roaming\npm\node_modules\bee-tools\node_modules\node-sass
> node scripts/build.js

> Binary found at D:\MyDownloads\Download\win32-x64-46_binding.node
Testing binary
Binary is fine

场景二:由于网络限制导致无法下载.node文件

1、安装node-sass时,报404:

> [email protected] install E:\node_modules\gulp-sass\node_modules\node-sass
> node scripts/install.js

Downloading binary from https://github.com/sass/node-sass/releases/download/v3.13.1/win32-x64-57_binding.node
//报错的的链接本身就失效了
Cannot download "https://github.com/sass/node-sass/releases/download/v3.13.1/win32-x64-57_binding.node":

HTTP error 404 Not Found

Hint: If github.com is not accessible in your location
      try setting a proxy via HTTP_PROXY, e.g.

      export HTTP_PROXY=http://example.com:1234

or configure npm proxy via

      npm config set proxy http://example.com:8080

2、解决方案一:

下载.node文件到本地,然后设置SASS_BINARY_PATH环境变量

  1. 从node命令行中复制.node文件下载链接并在浏览器打开下载文件(或直接访问node-sass)

  2. 文件下载成功后,在命令行工具输入下面指令,设置SASS_BINARY_PATH环境变量,目的是告诉程序直接使用本地的.node文件,无需从网上下载

set SASS_BINARY_PATH=.node所在的路径
  1. 配置完成,从新输入指令:
npm i node-sass -D --verbose

3、解决方案二:

使用 用友内部的镜像库ynpm下载

$ npm install ynpm-tool -g
$ ynpm install node-sass
  • ynpm 功能特性
  1. 根据用户网络进行自动匹配、自动切换、内网快速下载
  2. 镜像无需同步,下载即缓存,实现一次下载,全员共享
  3. 安全可靠,友互通域账号权限校验
  4. 内网发包配置简单、融合github设置sshk模式
  5. 提供强大的cli工具、模块化的实现、快速融合其他cli工具
  6. 不对npm的镜像源入侵

4、解决方案三:

使用淘宝镜像

> npm set sass_binary_site=https://npm.taobao.org/mirrors/node-sass/

或者

> npm install cnpm -g --registry=https://registry.npm.taobao.org
> cnpm install node-sass

yangchch6 avatar Jan 10 '19 12:01 yangchch6

怎么用 淘宝镜像呢

fridaydream avatar Jan 10 '19 16:01 fridaydream

怎么用淘宝镜像呢

用 ynpm 下载,体验更佳

yangchch6 avatar Jan 11 '19 02:01 yangchch6

不降级node的解决办法: 点这里

lucian55 avatar Jan 15 '19 06:01 lucian55