npm下載包很慢和node-sass編譯錯誤的解決辦法


最近研究一個ionic cordova angular2的前端項目 發現npm install下載包非常慢的問題 最近整理了一些解決這些問題的方法。

1.通過config命令修改https為http

 
        
npm config set registry http://registry.npmjs.org  npm info underscore
 
        

(如果上面配置正確這個命令會有字符串response)

2.命令行指定

 
        
npm --registry http://registry.cnpmjs.org info underscore
 
        
 
        

3.使用淘寶鏡像地址

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

  

如果上面的npm地址不行的話,大家可以參考一下方式

地址:http://www.uedbox.com/npm-install-slow-solution/

 

 

 

遇到問題解決如下:

由於某些不可描述的原因,利用npm進行安裝模塊的時候會發生xxx下載失敗的情況node-sass尤其的頻繁,或者說node-sass的二進制文件是接近百分百失敗的,即使用yarn安裝也依舊在這個點失敗,以下是完整的解決方案。

 

方案一:

  首先,我們需要提前下載node-sass的二進制文件,這個文件可以去cnpm倉庫下載或者node-sass的github上去下載,在下載之前我們需要先查看電腦的系統的版本,來確定適合哪個版本的二進制文件,查看版本的指令如下:

node -p "[process.platform, process.arch, process.versions.modules].join('-')"

輸入這個指令后會彈出一個系統版本,比如我這彈出的是 win32-x64-48,則我就需要去以下兩個地址中任意一個下載 win32-x64-48_binding.node 這個文件(后綴為node的文件)到本地:

  cnpm: https://npm.taobao.org/mirrors/node-sass/

  github: https://github.com/sass/node-sass/releases

下載完保存到任意位置,最好放置到package.json所在位置。然后我們需要手動指定node-sass二進制文件的下載源為下載的那個文件(比如我的是在e盤下的web文件夾內),以下是npm與yanr的指令:

npm:

npm config set sass-binary-path e:/web/win32-x64-48_binding.node

yran:

yarn config set sass-binary-path e:/web/win32-x64-48_binding.node

然后我們即可用正常指令下載了。注意:此方法會綁定為本地文件,即無法更新node-sass了~~如果不希望這么做,請使用第二種方案。

 

站長推薦:

方案二:

此方案將把下載源指定為cnpm倉庫:

全部的下載源指向cnpm的指令:

  npm :

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

  yarn :

yarn config set registry http://registry.npm.taobao.org

 只指定node-sass的下載源:

  npm:

npm config set sass-binary-site http://npm.taobao.org/mirrors/node-sass

  yarn:

yarn config set sass-binary-site http://npm.taobao.org/mirrors/node-sass

  然后我可以正常使用npm或者yarn進行下載了~

最后,關於如何使用cnpm代替npm。。。。直接npm install cnpm -g就好了-。-~~~~  然后就可以直接用cnpm install XXX等指令安裝了。

最后使用  cnpm install node-sass 下載這個插件就好了。 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM