npm install 時偶爾遇到報錯:沒有安裝python或node-sass 安裝失敗的問題,百度之后發現是被牆了,但根據百度的方法換了淘寶鏡像和用了vpn都安裝失敗,最后發現原來是因為沒有卸載之前安裝失敗的包導致的。文中給出了兩種報錯問題,使用淘寶鏡像或者使用yarn,找不到當前環境的綁定可以刪除重跑。
node-sass 安裝失敗的原因
npm 安裝 node-sass 依賴時,會從 github.com 上下載 .node 文件。由於國內網絡環境的問題,這個下載時間可能會很長,甚至導致超時失敗。
這是使用 sass 的同學可能都會遇到的郁悶的問題。
解決方案就是使用其他源,或者使用工具下載,然后將安裝源指定到本地。
解決方法一:使用淘寶鏡像源(推薦)
設置變量 sass_binary_site,指向淘寶鏡像地址。示例:
npm i node-sass --sass_binary_site=https://npm.taobao.org/mirrors/node-sass/ // 也可以設置系統環境變量的方式。示例 // 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
或者設置全局鏡像源:
npm config set sass_binary_site https://npm.taobao.org/mirrors/node-sass/
之后再涉及到 node-sass 的安裝時就會從淘寶鏡像下載。
解決方法二:使用 cnpm
使用 cnpm 安裝 node-sass 會默認從淘寶鏡像源下載,也是一個辦法:
cnpm install node-sass
解決方法三:創建.npmrc文件
在項目根目錄創建.npmrc文件,復制下面代碼到該文件。
phantomjs_cdnurl=http://cnpmjs.org/downloads
sass_binary_site=https://npm.taobao.org/mirrors/node-sass/
registry=https://registry.npm.taobao.org
保存后 刪除之前安裝失敗的包(第一次安裝請跳過此步)
npm uninstall node-sass
重新安裝
npm install node-sass
解決方法四:下載 .node 到本地
去根據版本號、系統環境,選擇下載 .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.taobao.org/mirrors/node-sass/
參考:https://segmentfault.com/a/1190000010984731?utm_source=tag-newest
問題:[npm install 報node-sass錯誤]
npm WARN Error: EPERM: operation not permitted, scandir 'E:\zkh360\Zkh360.Web.Admin\app\node_modules\har-validator\node_modules' npm WARN { Error: EPERM: operation not permitted, scandir 'E:\zkh360\Zkh360.Web.Admin\app\node_modules\har-validator\node_modules' npm WARN stack: 'Error: EPERM: operation not permitted, scandir \'E:\\zkh360\\Zkh360.Web.Admin\\app\\node_modules\\har-validator\\node_modules\'', npm WARN errno: -4048, npm WARN code: 'EPERM', npm WARN syscall: 'scandir', npm WARN path: 'E:\\zkh360\\Zkh360.Web.Admin\\app\\node_modules\\har-validator\\node_modules' } npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! node-sass@3.13.1 postinstall: `node scripts/build.js`
npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the node-sass@3.13.1 postinstall script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
問題:Node Sass找不到當前環境的綁定
Node Sass could not find a binding for your current environment
ERROR in Missing binding /Users/warren/Sites/random-docs/ my-cms/node_modules/node-sass/vendor/darwin-x64-11/binding.node
Node Sass could not find a binding for your current environment: OS X 64-bit with Node 0.10.x
解決方案。刪除node_modules並運行npm install然后npm rebuild node-sass 什么都不做。
stackoverflow原文