关于npm/node-sass安装依赖报错的解决方案

每次拉新项目安装依赖的时候,总是会报各种各样的错误

npm install

一开始还以为是哪个文件有问题,后来明白了,一切都是因为网络。。。。
npm 默认连接的服务器是国外的,网络很不稳定。。。。所以极其容易出错

后来每次换电脑,我都会直接将npm连接的服务器设置为淘宝源(淘宝架设的与npm官方同步数据的服务器)国内访问丝滑流畅

npm config set registry https://registry.npm.taobao.org

可是后来还是遇到了问题
仔细看报错信息,是node-sass下载失败了。
我以为是node-sass版本问题,后来以为是node的版本问题(node太新的话,不兼容老版本node-sass)
但我还是栽了。。。。。,它依然还是网络问题!!!

仔细看下面安装Node-sass时的报错信息

Downloading binary from https://github.com/sass/node-sass/releases/download/v4.11.0/win32-x64-72_binding.node
Cannot download "https://github.com/sass/node-sass/releases/download/v4.11.0/win32-x64-72_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

发现没有

Cannot download "https://github.com/sass/node-sass/releases/download/v4.11.0/win32-x64-72_binding.node":

无法下载,地址是什么? https://github.com/
回忆一下,我们平时上gayhub时的卡顿酸爽?
是的,node-sass在安装过程中,有一步是下载win32-x64-72_binding.node这个文件,而它请求的是github地址,所以我们现在要把这个地址也替换成淘宝源

npm install -g mirror-config-china --registry=http://registry.npm.taobao.org

设置好以后,我们进行

npm install

大功告成!(看Downloading的地址是不是变成了taobao.org)

Downloading binary from https://npm.taobao.org/mirrors/node-sass/v4.13.1/win32-x64-72_binding.node
Download complete  ] - :
Binary saved to E:\project\nj-mc-poc-pc\node_modules\node-sass\vendor\win32-x64-72\binding.node
Caching binary to C:\Users\Administrator\AppData\Roaming\npm-cache\node-sass\4.13.1\win32-x64-72_binding.node

> [email protected] postinstall E:\project\nj-mc-poc-pc\node_modules\node-sass
> node scripts/build.js

Binary found at E:\project\nj-mc-poc-pc\node_modules\node-sass\vendor\win32-x64-72\binding.node
Testing binary
Binary is fine
npm WARN [email protected] requires a peer of html-webpack-plugin@^3.0.0 but none is installed. You must install peer dependencies yourself.    
npm WARN [email protected] requires a peer of @antv/data-set@^0.9.6 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] No repository field.

+ [email protected]
added 84 packages from 92 contributors in 23.394s

28 packages are looking for funding
  run `npm fund` for details

综合起来就是

npm config set registry https://registry.npm.taobao.org
npm install -g mirror-config-china --registry=http://registry.npm.taobao.org
npm install

不是我针对谁,在座的报错,都是垃圾!!!

你可能感兴趣的:(关于npm/node-sass安装依赖报错的解决方案)