npm 安裝依賴 報這個錯時: gyp: No Xcode or CLT version detected!

今天接盤一個公司的項目,因爲疫情原因,公司發不出工資,很多人都離開了,而我被迫留守,所以要接手離職同事的項目。

廢話不多說,進入主題。

當我開心的拉完項目,準備裝好依賴開始一頓debug操作時,發現.. 項目跑不動,報錯說缺了node-sass模塊,好吧,那就install一下,結果沒裝成功,基本可以確定是這個絆腳石害我跑不起來項目了。接着,先品一品報錯內容,報錯如下:


Building: /usr/local/bin/node /Users/money/work/dunming-ops-front/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 [ '/usr/local/bin/node',
gyp verb cli   '/Users/money/work/dunming-ops-front/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 [email protected]
gyp info using [email protected] | darwin | x64
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" in the PATH
gyp verb `which` succeeded python2 /usr/bin/python2
gyp verb check python version `/usr/bin/python2 -c "import sys; print "2.7.16
gyp verb check python version .%s.%s" % sys.version_info[:3];"` returned: %j
gyp verb get node dir no --target version specified, falling back to host node version: 10.7.0
gyp verb command install [ '10.7.0' ]
gyp verb install input version string "10.7.0"
gyp verb install installing version: 10.7.0
gyp verb install --ensure was passed, so won't reinstall if already installed
gyp verb install version is already installed, need to check "installVersion"
gyp verb got "installVersion" 9
gyp verb needs "installVersion" 9
gyp verb install version is good
gyp verb get node dir target node version installed: 10.7.0
gyp verb build dir attempting to create "build" dir: /Users/money/work/dunming-ops-front/node_modules/node-sass/build
gyp verb build dir "build" dir needed to be created? /Users/money/work/dunming-ops-front/node_modules/node-sass/build
gyp verb build/config.gypi creating config file
gyp verb build/config.gypi writing out config file: /Users/money/work/dunming-ops-front/node_modules/node-sass/build/config.gypi
gyp verb config.gypi checking for gypi file: /Users/money/work/dunming-ops-front/node_modules/node-sass/config.gypi
gyp verb common.gypi checking for gypi file: /Users/money/work/dunming-ops-front/node_modules/node-sass/common.gypi
gyp verb gyp gyp format was not specified; forcing "make"
gyp info spawn /usr/bin/python2
gyp info spawn args [ '/Users/money/work/dunming-ops-front/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'make',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/money/work/dunming-ops-front/node_modules/node-sass/build/config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/money/work/dunming-ops-front/node_modules/node-gyp/addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/money/.node-gyp/10.7.0/include/node/common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=/Users/money/.node-gyp/10.7.0',
gyp info spawn args   '-Dnode_gyp_dir=/Users/money/work/dunming-ops-front/node_modules/node-gyp',
gyp info spawn args   '-Dnode_lib_file=/Users/money/.node-gyp/10.7.0/<(target_arch)/node.lib',
gyp info spawn args   '-Dmodule_root_dir=/Users/money/work/dunming-ops-front/node_modules/node-sass',
gyp info spawn args   '-Dnode_engine=v8',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--no-parallel',
gyp info spawn args   '--generator-output',
gyp info spawn args   'build',
gyp info spawn args   '-Goutput_dir=.' ]
No receipt for 'com.apple.pkg.CLTools_Executables' found at '/'.

No receipt for 'com.apple.pkg.DeveloperToolsCLILeo' found at '/'.

No receipt for 'com.apple.pkg.DeveloperToolsCLI' found at '/'.

gyp: No Xcode or CLT version detected!
gyp ERR! configure error 
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onCpExit (/Users/money/work/dunming-ops-front/node_modules/node-gyp/lib/configure.js:345:16)
gyp ERR! stack     at ChildProcess.emit (events.js:182:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:237:12)
gyp ERR! System Darwin 19.4.0
gyp ERR! command "/usr/local/bin/node" "/Users/money/work/dunming-ops-front/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd /Users/money/work/dunming-ops-front/node_modules/node-sass
gyp ERR! node -v v10.7.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok 
Build failed with error code: 1
npm WARN @intervolga/[email protected] requires a peer of webpack@^4.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN @vue/[email protected] requires a peer of webpack@>=4.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of ajv@^6.9.1 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of webpack@^4.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of webpack@>=4.0.0 < 6.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of webpack@^4.4.0 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of webpack@^4.0.0 but none is installed. You must install peer dependencies yourself.

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.

仔細閱讀一番,無果,因爲還沒遇到過這類問題,所以花了一個多小時搜了下,網上結論大都是更新xcode或者可以更新xcode的一個小組件,xcode-select。

最後選擇重裝xcode-select,因爲xcode好幾個g呢,下載完都天亮了。

注意事項:

要刪了本地的xcode-select相關文件,一開始以爲可以直接裝,覆蓋了,但是裝不了,刪了之後就可以了。

 sudo rm -rf $(xcode-select -print-path)

然後再安裝之

 sudo xcode-select --install

裝完之後再安裝你想安裝的依賴/模塊,就可以啦!

最後吐槽下,sass這個老東西,發現接手的這個項目用的包,技術都不是我喜歡的簡潔,快速方便。less就很香啊,不需要依賴ruby,直接裝就好了,害我裝這麼多東西。只能說一下舊的歷史遺留下來的東西好用但是麻煩,畢竟是過去的

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章