前言:
今天一公司某位同學突然需要啟動一個很久以前的項目(其實也沒多久,只是好久沒有這個項目的新需求,所以就塵封了,項目還在運行的)
然后就
啟動報錯了~~
倒吸一口冷氣啊支鸡。。趁窃。
這是咋了牧挣,這是咋了
看著上面
Node Sass could not find a binding for your current environment: Windows 32-bit with Node.js 10.x
這行報錯,據(jù)我目測這位同學是升級了node到10.x版本然后node-sass不支持醒陆。
情況的確是這個情況瀑构,之前是使用node8.11.3前一段時間換成了10.15.3
so~
重新安裝一下依賴吧
yarn
然后我驚呆了
這怎么這么多警告,什么鬼東西
好吧刨摩,警告先跳過去吧寺晌,項目跑起來再說,看起來都是node-sass的警告
直到我看到了報錯
error D:\work\m.dongdao\node_modules\node-sass: Command failed.
Exit code: 1
Command: node scripts/build.js
Arguments:
Directory: D:\work\m.dongdao\node_modules\node-sass
Output:
Building: C:\Program Files (x86)\nodejs\node.exe D:\work\m.dongdao\node_modules\node-gyp\bin\node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
gyp info it worked if it ends with ok
gyp verb cli [ 'C:\\Program Files (x86)\\nodejs\\node.exe',
gyp verb cli 'D:\\work\\m.dongdao\\node_modules\\node-gyp\\bin\\node-gyp.js',
gyp verb cli 'rebuild',
gyp verb cli '--verbose',
gyp verb cli '--libsass_ext=',
gyp verb cli '--libsass_cflags=',
gyp verb cli '--libsass_ldflags=',
gyp verb cli '--libsass_library=' ]
gyp info using node-gyp@3.8.0
gyp info using node@10.15.3 | win32 | ia32
gyp verb command rebuild []
gyp verb command clean []
gyp verb clean removing "build" directory
gyp verb command configure []
gyp verb check python checking for Python executable "python2.7" in the PATH
gyp verb `which` failed Error: not found: python2.7
gyp verb `which` failed at getNotFoundError (D:\work\m.dongdao\node_modules\which\which.js:13:12)
gyp verb `which` failed at F (D:\work\m.dongdao\node_modules\which\which.js:68:19)
gyp verb `which` failed at E (D:\work\m.dongdao\node_modules\which\which.js:80:29)
gyp verb `which` failed at D:\work\m.dongdao\node_modules\which\which.js:89:16
gyp verb `which` failed at D:\work\m.dongdao\node_modules\isexe\index.js:42:5
gyp verb `which` failed at D:\work\m.dongdao\node_modules\isexe\windows.js:36:5
gyp verb `which` failed at FSReqWrap.oncomplete (fs.js:153:21)
gyp verb `which` failed python2.7 { Error: not found: python2.7
gyp verb `which` failed at getNotFoundError (D:\work\m.dongdao\node_modules\which\which.js:13:12)
gyp verb `which` failed at F (D:\work\m.dongdao\node_modules\which\which.js:68:19)
gyp verb `which` failed at E (D:\work\m.dongdao\node_modules\which\which.js:80:29)
gyp verb `which` failed at D:\work\m.dongdao\node_modules\which\which.js:89:16
gyp verb `which` failed at D:\work\m.dongdao\node_modules\isexe\index.js:42:5
gyp verb `which` failed at D:\work\m.dongdao\node_modules\isexe\windows.js:36:5
gyp verb `which` failed at FSReqWrap.oncomplete (fs.js:153:21)
gyp verb `which` failed stack:
gyp verb `which` failed 'Error: not found: python2.7\n at getNotFoundError (D:\\work\\m.dongdao\\node_modules\\which\\which.js:13:12)\n at F (D:\\work\\m.dongdao\\node_modules\\which\\which.js:68:19)\n at E (D:\\work\\m.dongdao\\node_modules\\which\\which.js:80:29)\n at D:\\work\\m.dongdao\\node_modules\\which\\which.js:89:16\n at D:\\work\\m.dongdao\\node_modules\\isexe\\index.js:42:5\n at D:\\work\\m.dongdao\\node_modules\\isexe\\windows.js:36:5\n at FSReqWrap.oncomplete (fs.js:153:21)',
gyp verb `which` failed code: 'ENOENT' }
gyp verb could not find "python2.7". checking python launcher
gyp verb could not find "python2.7". guessing location
gyp verb ensuring that file exists: C:\Python27\python.exe
gyp ERR! configure error
gyp ERR! stack Error: Can't find Python executable "python2.7", you can set the PYTHON env variable.
gyp ERR! stack at PythonFinder.failNoPython (D:\work\m.dongdao\node_modules\node-gyp\lib\configure.js:484:19)
gyp ERR! stack at PythonFinder.<anonymous> (D:\work\m.dongdao\node_modules\node-gyp\lib\configure.js:509:16)
gyp ERR! stack at callback (D:\work\m.dongdao\node_modules\graceful-fs\polyfills.js:295:20)
gyp ERR! stack at FSReqWrap.oncomplete (fs.js:153:21)
gyp ERR! System Windows_NT 6.1.7601
gyp ERR! command "C:\\Program Files (x86)\\nodejs\\node.exe" "D:\\work\\m.dongdao\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd D:\work\m.dongdao\node_modules\node-sass
gyp ERR! node -v v10.15.3
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
ERR!
ERR!
ERR!
我覺得我需要認真對待了
從報錯信息上看
(1)這次安裝過程中python2.7沒找到
(2)錯誤都是gyp開頭码邻,node-gyp是跨平臺調(diào)用的node插件折剃,比如可以調(diào)用python,c++等
(3)這兩個錯誤導致node-sass安裝失敗
看起來只要把python2.7安裝就可以了
npm install --global --production windows-build-tools
這個包會在電腦上安裝三個語言支持
1像屋、python(v2.7 怕犁,3.x不支持);
2、visual C++ Build Tools,或者 (vs2015以上(包含15))
3己莺、.net framework 4.5.1
靜靜等待····················
靜靜等待····················
靜靜等待····················
ok奏甫!可以了
yarn && npm run dev
走起,真男人從不回頭看爆炸
天真的我又一次被現(xiàn)實擊垮凌受,剛一頓操作連報錯信息都沒變?
是不是過分了阵子,我都給你安裝上了,你怎么還找不到呢
嗯~可能是因為本機python不是2.7的原因吧胜蛉,那改一下環(huán)境變量挠进,把python指向到python2.7去
重啟命令行色乾,再試一次
yarn && npm run dev
走起,真男人從不回頭看爆炸
perfect~
我決定看一看node-gyp 嗯君旦,這玩意需要運行在node32位的版本上
我的node也不是32位啊澎办,難道我要換一個32位的node?
就在我等待下載node32位安裝包的過程中金砍,我覺得這個問題不會只有我遇到過局蚀,百度一下,還真不少人遇到恕稠!
但每個人使用的node-sass的版本是不一樣的琅绅,我決定升級一下node-sass試試,現(xiàn)在項目的版本是4.9.0是支持node10.x的谱俭,那就直接升級成node-sass@4.13.1這是目前最新的穩(wěn)定版本了奉件。
嗯~ 干的漂亮宵蛀,還是安裝不上
(事態(tài)逐漸失控昆著,我安慰前端同學,別慌)
這個時候做個試驗吧术陶,新建一個文件夾
npm init && npm install node-sass@4.13.1 --save-dev
還是不行凑懂,這就不是項目里面各個包依賴關(guān)系出問題了,而是在node10.15.3下yarn npm 安裝node-sass都安裝失敗
不科學~~~
本著死馬當活馬醫(yī)的態(tài)度梧宫,我又試了一下
cnpm install node-sass@4.13.1 --save-dev
emmmmmmmmmmmmm
成功了~
CTMD
為什么
cnpm 和 npm 有什么區(qū)別
npm
是nodejs 的包管理器,用于node插件管理 ( 包括安裝,卸載 ,管理 依賴等 )
cnpm
這是一個完整 npmjs.org 鏡像接谨,你可以用此代替官方版本(只讀),同步頻率目前為 10分鐘 一次以保證盡量與官方服務同步
結(jié):
emmmmmm
所以我只能把這次問題歸結(jié)為網(wǎng)絡波動了~
我建了一個前端微信交流群塘匣,歡迎大家加入脓豪,qq中轉(zhuǎn)群號:1076484243