node-sass 安裝失敗的原因npm 安裝 node-sass 依賴時,,會從 github.com 上下載 .node 文件。由于國內(nèi)網(wǎng)絡(luò)環(huán)境的問題,,這個下載時間可能會很長,,甚至導(dǎo)致超時失敗。 解決方案就是使用其他源,,或者使用工具下載,然后將安裝源指定到本地,。 解決方法一:使用淘寶鏡像源(推薦)設(shè)置變量 sass_binary_site,,指向淘寶鏡像地址。示例 npm i node-sass --sass_binary_site=https://npm./mirrors/node-sass/ // 也可以設(shè)置系統(tǒng)環(huán)境變量的方式,。示例 // linux,、mac 下 SASS_BINARY_SITE=https://npm./mirrors/node-sass/ npm install node-sass // window 下 set SASS_BINARY_SITE=https://npm./mirrors/node-sass/ && npm install node-sass 或者設(shè)置全局鏡像源: npm config set sass_binary_site https://npm./mirrors/node-sass/ 之后再涉及到 node-sass 的安裝時就會從淘寶鏡像下載。 解決方法二:使用 cnpm使用 cnpm 安裝 node-sass 會默認(rèn)從淘寶鏡像源下載,,也是一個辦法: cnpm install node-sass 解決方法三:創(chuàng)建.npmrc文件在項目根目錄創(chuàng)建.npmrc文件,,復(fù)制下面代碼到該文件。 phantomjs_cdnurl=http:///downloads sass_binary_site=https://npm./mirrors/node-sass/ registry=https://registry.npm. 保存后 刪除之前安裝失敗的包(第一次安裝請?zhí)^此步) npm uninstall node-sass 重新安裝 npm uninstall node-sass 作者后來另一個項目在沒有使用VPN的情況下測試此方法,,安裝時報錯 ERR! [email protected] postinstall: `node scripts/build.js 改用方法一成功,。 解決方法四:下載 .node 到本地到這里去根據(jù)版本號、系統(tǒng)環(huán)境,,選擇下載 .node 文件,,然后安裝時,指定變量 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./mirrors/node-sass/ 相關(guān)錯誤提示 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 [email protected] requires a peer of mocha@>=1.18 <4 but none was installed. npm WARN [email protected] No repository field. npm WARN [email protected] scripts['server'] should probably be scripts['start']. npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! [email protected] postinstall: `node scripts/build.js` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the [email protected] 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 |
|