整理 node-sass 安裝失敗的原因及解決辦法(小結(jié))
npm install 時(shí)偶爾遇到報(bào)錯(cuò):沒有安裝python或node-sass 安裝失敗的問題,百度之后發(fā)現(xiàn)是被墻了,但根據(jù)百度的方法換了淘寶鏡像和用了vpn都安裝失敗,最后發(fā)現(xiàn)原來是因?yàn)闆]有卸載之前安裝失敗的包導(dǎo)致的。作者本人最后的解決方案是npm uninstall node-sass,然后使用VPN重新安裝了一遍就成功了。不能翻墻的同學(xué)請看下文
node-sass 安裝失敗的原因
npm 安裝 node-sass 依賴時(shí),會(huì)從 github.com 上下載 .node 文件。由于國內(nèi)網(wǎng)絡(luò)環(huán)境的問題,這個(gè)下載時(shí)間可能會(huì)很長,甚至導(dǎo)致超時(shí)失敗。
這是使用 sass 的同學(xué)可能都會(huì)遇到的郁悶的問題。
解決方案就是使用其他源,或者使用工具下載,然后將安裝源指定到本地。
解決方法一:使用淘寶鏡像源(推薦)
設(shè)置變量 sass_binary_site,指向淘寶鏡像地址。示例:
npm i node-sass --sass_binary_site=https://npm.taobao.org/mirrors/node-sass/ // 也可以設(shè)置系統(tǒng)環(huán)境變量的方式。示例 // linux、mac 下 SASS_BINARY_SITE=https://npm.taobao.org/mirrors/node-sass/ npm install node-sass // window 下 set SASS_BINARY_SITE=https://npm.taobao.org/mirrors/node-sass/ && npm install node-sass
或者設(shè)置全局鏡像源:
npm config set sass_binary_site https://npm.taobao.org/mirrors/node-sass/
之后再涉及到 node-sass 的安裝時(shí)就會(huì)從淘寶鏡像下載。
解決方法二:使用 cnpm
使用 cnpm 安裝 node-sass 會(huì)默認(rèn)從淘寶鏡像源下載,也是一個(gè)辦法:
cnpm install node-sass
解決方法三:創(chuàng)建.npmrc文件
在項(xiàng)目根目錄創(chuàng)建.npmrc文件,復(fù)制下面代碼到該文件。
phantomjs_cdnurl=http://cnpmjs.org/downloads sass_binary_site=https://npm.taobao.org/mirrors/node-sass/ registry=https://registry.npm.taobao.org
保存后 刪除之前安裝失敗的包(第一次安裝請?zhí)^此步)
npm uninstall node-sass
重新安裝
npm install node-sass
作者后來另一個(gè)項(xiàng)目在沒有使用VPN的情況下測試此方法,安裝時(shí)報(bào)錯(cuò) ERR! node-sass@3.8.0 postinstall: `node scripts/build.js 改用方法一成功。
解決方法四:下載 .node 到本地
到這里去根據(jù)版本號、系統(tǒng)環(huán)境,選擇下載 .node 文件,然后安裝時(shí),指定變量 sass_binary_path,如:
npm i node-sass --sass_binary_path=/Users/lzwme/Downloads/darwin-x64-48_binding.node
安裝失敗后重新安裝問題
之前安裝失敗,再安裝就不去下載了,怎么辦呢?那就先卸載再安裝:
npm uninstall node-sass npm i node-sass --sass_binary_site=https://npm.taobao.org/mirrors/node-sass/
相關(guān)錯(cuò)誤提示
提示沒有安裝python、build失敗等,如:
gyp ERR! configure error gyp ERR! stack Error: Can't find Python executable "C:\Users\zhuon\AppData\Local\Programs\Python\Python36\python.EXE", you can set the PYTHON env variable. gyp ERR! stack at PythonFinder.failNoPython (G:\Workspace\ManYan\manyan-nav\node_modules\node-gyp\lib\configure.js:483:19) gyp ERR! stack at PythonFinder.<anonymous> (G:\Workspace\ManYan\manyan-nav\node_modules\node-gyp\lib\configure.js:508:16) gyp ERR! stack at G:\Workspace\ManYan\manyan-nav\node_modules\graceful-fs\polyfills.js:284:29 gyp ERR! stack at FSReqWrap.oncomplete (fs.js:152:21) gyp ERR! System Windows_NT 10.0.15063 gyp ERR! command "C:\\dev\\nodejs\\node.exe" "G:\\Workspace\\ManYan\\manyan-nav\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library=" gyp ERR! cwd G:\Workspace\ManYan\manyan-nav\node_modules\node-sass gyp ERR! node -v v8.4.0 gyp ERR! node-gyp -v v3.6.2 gyp ERR! not ok Build failed npm WARN co-mocha@1.2.0 requires a peer of mocha@>=1.18 <4 but none was installed. npm WARN egg-restapi-module-tool@1.0.0 No repository field. npm WARN egg-restapi-module-tool@1.0.0 scripts['server'] should probably be scripts['start']. npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! node-sass@3.8.0 postinstall: `node scripts/build.js` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the node-sass@3.8.0 postinstall script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! D:\nodejs\cache\_logs\2017-09-02T16_06_24_298Z-debug.log
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
nodejs中向HTTP響應(yīng)傳送進(jìn)程的輸出
這篇文章主要介紹了nodejs中向HTTP響應(yīng)傳送進(jìn)程的輸出 ,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2017-03-03使用socket.io實(shí)現(xiàn)簡單聊天室案例
這篇文章主要介紹了使用socket.io實(shí)現(xiàn)簡單聊天室案例,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-01-01淺談Express.js解析Post數(shù)據(jù)類型的正確姿勢
這篇文章主要介紹了Express.js解析Post數(shù)據(jù)類型的正確姿勢,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2019-05-05node實(shí)現(xiàn)簡單的反向代理服務(wù)器
本篇文章主要介紹了node實(shí)現(xiàn)簡單的反向代理,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-07-07nodejs+axios爬取html出現(xiàn)中文亂碼并解決示例
這篇文章主要為大家介紹了nodejs+axios爬取html出現(xiàn)中文亂碼示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-06-06node.js 使用 net 模塊模擬 websocket 握手進(jìn)行數(shù)據(jù)傳遞操作示例
這篇文章主要介紹了node.js 使用 net 模塊模擬 websocket 握手進(jìn)行數(shù)據(jù)傳遞操作,結(jié)合實(shí)例形式分析了node.js基于net模塊模擬 websocket握手相關(guān)原理及進(jìn)行數(shù)據(jù)傳遞具體操作技巧,需要的朋友可以參考下2020-02-02node.js調(diào)用C++函數(shù)的方法示例
這篇文章主要介紹了node.js調(diào)用C++函數(shù)的方法示例,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-09-09