NPM相關(guān)命令之報錯node-gyp...的解決方法
NPM 相關(guān)命令,報錯 node-gyp… 的解決方法
'node-gyp-build' is not recognized as an internal or external command, operable program or batch file.
npm ERR! gyp verb `which` failed Error: not found: python2
…
相關(guān)的異常信息
> node-gyp-build
errorOut='node-gyp-build' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! utf-8-validate@5.0.9 install: `node-gyp-build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the utf-8-validate@5.0.9 install 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:\app\nodejs\npm-cache\_logs\2022-06-10T00_53_04_766Z-debug.logcommand='D:\app\nodejs\node.exe' 'D:\app\nvm\v14.7.0\node_modules\npm\bin\npm-cli.js' rebuild utf-8-validate@5.0.9
workingDir=
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! lx-music-desktop@1.22.0-beta pack:dir: `node build-config/pack.js && electron-builder --dir`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the lx-music-desktop@1.22.0-beta pack:dir 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:\app\nodejs\npm-cache\_logs\2022-06-10T00_53_04_842Z-debug.log
通用的解決方案
1. 在線安裝,適合擁有純凈 Windows 開發(fā)環(huán)境的用戶(沒有安裝過 Python, Visual Studio 等…)
# 全局設(shè)置淘寶鏡像(配置過的老鳥可忽略此步驟) $ npm config set registry https://registry.npm.taobao.org # 單次使用淘寶鏡像(會使用的老鳥可忽略此步驟) $ npm install -g node-gyp --registry=https://registry.npm.taobao.org $ npm install -g --production windows-build-tools --registry=https://registry.npm.taobao.org
2. 手動安裝,針對擁有非純凈 Windows 開發(fā)環(huán)境的老鳥(安裝過 Python, Visual Studio 等…)
重點注意: 等到
Starting installation...
命令字樣出現(xiàn)后,立馬Ctrl + C
終止后面的安裝過程
!!! 因為我們必須自定義安裝這兩個新環(huán)境,才能不影響我們系統(tǒng)中已安裝的 python 和 vs 等環(huán)境。
巧妙獲取 python2 和 msvs_version 相關(guān)版本的安裝包
$ npm install --global --production windows-build-tools npm WARN deprecated windows-build-tools@5.2.2: Node.js now includes build tools for Windows. You probably no longer need this tool. See https://github.com/felixrieseberg/windows-build-tools for details. npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142 npm WARN deprecated har-validator@5.1.5: this library is no longer supported npm WARN deprecated uuid@3.4.0: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details. > windows-build-tools@5.2.2 postinstall D:\app\nodejs\node_global\node_modules\windows-build-tools > node ./dist/index.js Downloading python-2.7.15.amd64.msi [============================================>] 100.0% of 20.2 MB (9 MB/s) Downloaded python-2.7.15.amd64.msi. Saved to C:\Users\cpw\.windows-build-tools\python-2.7.15.amd64.msi. Downloading vs_BuildTools.exe [============================================>] 100.0% of 1.12 MB (1.12 MB/s) Downloaded vs_BuildTools.exe. Saved to C:\Users\cpw\.windows-build-tools\vs_BuildTools.exe. Starting installation... Launched installers, now waiting for them to finish. This will likely take some time - please be patient! Status from the installers: ---------- Visual Studio Build Tools ---------- Still waiting for installer log file... ------------------- Python -------------------- Still waiting for installer log file...^C
手動安裝 python2 和 msvs_version 到自定義目錄
# 靜默安裝 python2 到指定的目錄 Microsoft Windows [版本 10.0.19044.1706] (c) Microsoft Corporation。保留所有權(quán)利。 C:\Users\cpw\.windows-build-tools>msiexec /a C:\Users\cpw\.windows-build-tools\python-2.7.15.amd64.msi /quiet TargetDir="C:/app/pvm/v2.7.15" # 靜默安裝 vs_BuildTools 到默認的目錄 C:\Users\cpw\.windows-build-tools>vs_BuildTools.exe /quiet PrependPath=0 Include_launcher=0 Include_test=0 Include_tcltk=0 Shortcuts=0
全局設(shè)置 python2 和 msvs_version 環(huán)境變量
# 全局設(shè)置 python2 環(huán)境變量 $ npm config set python2 "C:\Python27\python.exe" # 全局設(shè)置 buildTools 環(huán)境變量 $ npm config set msvs_version "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools"
查看 NPM 全局配置
$ npm config list -g ; cli configs global = true metrics-registry = "https://registry.npm.taobao.org/" scope = "" user-agent = "npm/6.14.13 node/v14.17.0 win32 x64" ; userconfig C:\Users\cpw\.npmrc CHROMEDRIVER_CDNURL = "https://npm.taobao.org/mirrors/chromedriver" ELECTRON_BUILDER_BINARIES_MIRROR = "https://npm.taobao.org/mirrors/electron-builder-binaries/" ELECTRON_MIRROR = "https://npm.taobao.org/mirrors/electron/" NVM_NODEJS_ORG_MIRROR = "https://npm.taobao.org/mirrors/node" OPERADRIVER = "https://npm.taobao.org/mirrors/operadriver" PYTHON_MIRROR = "https://npm.taobao.org/mirrors/python" cache = "D:\\app\\nodejs\\npm-cache" chromedriver_cdnurl = "https://npm.taobao.org/mirrors/chromedriver" electron-builder-binaries_mirror = "https://npm.taobao.org/mirrors/electron-builder-binaries/" electron_mirror = "https://npm.taobao.org/mirrors/electron/" msvs_version = "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\BuildTools" node_sqlite3_binary_host_mirror = "http://npm.taobao.org/mirrors" phantomjs_cdnurl = "https://npm.taobao.org/mirrors/phantomjs" prefix = "D:\\app\\nodejs\\node_global" python = "?D:\\app\\pvm\\v2.7.15\\python.exe" registry = "https://registry.npm.taobao.org/" sass_binary_site = "https://npm.taobao.org/mirrors/node-sass/" strict-ssl = false ; node bin location = D:\app\nodejs\node.exe ; cwd = D:\code\NodejsProjects\lx-music-desktop ; HOME = C:\Users\cpw ; "npm config ls -l" to show all defaults.
總結(jié)
到此這篇關(guān)于NPM相關(guān)命令之報錯node-gyp...解決的文章就介紹到這了,更多相關(guān)NPM報錯node-gyp...解決內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Node.js利用debug模塊打印出調(diào)試日志的方法
debug日志打印模塊主要實現(xiàn)功能是帶命名空間(模塊名)、時間戳、色彩輸出日志;將日志寫入文件;瀏覽器端使用;格式化函數(shù);支持自定義方法。下面這篇文章主要介紹了Node.js利用debug模塊打印出調(diào)試日志的方法,需要的朋友可以參考借鑒,下面來一起看看吧。2017-04-04Node.js中使用mongoose操作mongodb數(shù)據(jù)庫的方法
如何利用mongoose將數(shù)據(jù)寫入mongodb數(shù)據(jù)庫呢?操作方法很簡單,下面小編給大家分享Node.js中使用mongoose操作mongodb數(shù)據(jù)庫的方法,感興趣的朋友一起看看吧2017-09-09使用express+multer實現(xiàn)node中的圖片上傳功能
這篇文章主要介紹了使用express+multer實現(xiàn)node中的圖片上傳功能,需要的朋友可以參考下2018-02-02如何在Nestjs和Vue3中使用socket.io示例詳解
這篇文章主要為大家介紹了如何在Nestjs和Vue3中使用socket.io示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-08-08