npm安裝時的錯誤排查的方法
1.npm安裝時遇到error,從error1 處查看最初的報錯內(nèi)容比較準
2.根據(jù)error的內(nèi)容查看是哪個依賴項引起的錯,查閱package.json里對應的依賴版本和當前的node.js版本是否一致


3.缺少C++、python等環(huán)境,按照缺失項,安裝對應的運行環(huán)境
npm ERR! gyp verb check python checking for Python executable "python2" in the PATH
npm ERR! gyp verb `which` failed Error: not found: python2
4.缺少微軟C++相關的開發(fā)庫
gyp ERR! build error gyp ERR! stack Error: `C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe` failed with exit code: 1
關鍵字是Visual Studio,需要下載相關依賴


5.某些依賴鏈接已經(jīng)失效404
如下面這個會提示鏈接超時,并且手動打開對應的鏈接也是404頁面
> node-sass@3.13.1 install D:\workspace\node_modules\node-sass
> node scripts/install.jsDownloading binary from https://github.com/sass/node-sass/releases/download/v3.13.1/win32-x64-64_binding.node
Cannot download "https://github.com/sass/node-sass/releases/download/v3.13.1/win32-x64-64_binding.node":connect ETIMEDOUT 20.205.243.166:443
Timed out whilst downloading the prebuilt binary
Hint: If github.com is not accessible in your location
try setting a proxy via HTTP_PROXY, e.g.export HTTP_PROXY=http://example.com:1234
or configure npm proxy via
npm config set proxy http://example.com:8080

可以設置鏡像(淘寶的鏡像不一定好使)、單獨安裝失敗的依賴設置(鏈接必須得能訪問才行,老鏈接失效得多)

或者直接用命令安裝對應的缺失版本:
這里是在github上找到了對應原來缺失的sass 3.4.2版本庫文件
npm install git+https://github.com/sass/node-sass.git#v3.4.2 --save
6.某些依賴項可能是從github上以ssh拉取的,如果本地不配置github的ssh密鑰會一直timeout,配置完以后git可以拉取說明配置成功
checking installable status 就卡主,然后就timeout,看到了報錯內(nèi)容里有關鍵字git和ssh。
npm WARN deprecated domexception@1.0.1: Use your platform's native DOMException instead [ ...............] \ fetchMetadata: sill resolveWithNewModule camelcase@4.1.0
手動測試
D:\workspace\git-test>ssh -T git@github.com
ssh: connect to host github.com port 22: Connection timed outD:\workspace\git-test>git clone ssh://git@github.com/sohee-lee7/Squire.git
Cloning into 'Squire'...
ssh: connect to host github.com port 22: Connection timed out
fatal: Could not read from remote repository.Please make sure you have the correct access rights
and the repository exists.D:\workspace\git-test>git clone ssh://git@github.com/sohee-lee7/Squire.git
Cloning into 'Squire'...
remote: Enumerating objects: 3598, done.
remote: Total 3598 (delta 0), reused 0 (delta 0), pack-reused 3598
Receiving objects: 100% (3598/3598), 3.08 MiB | 1.59 MiB/s, done.
生成github密鑰,會在當前~/ssh生成圖中文件,還需要手動創(chuàng)建配置,讓git的ssh生效才行

7.某些依賴可能是從github上以http協(xié)議拉取的,國內(nèi)很多情況無法通過http或https訪問github,本地有vpn的話得手動給git配置上代理

npm報錯中出現(xiàn)了git.EXE ls-remote -h -t https://github.com/nhn/raphael.git這行,手動測試發(fā)現(xiàn)拉不下來就還是git網(wǎng)絡問題

8.某些依賴可能是npm直接拉去二進制流形式下載的,同理,npm也需要配置代理 ,但是本人測試以后發(fā)現(xiàn)npm配置代理會卡主,但是可以對cmd窗口配置臨時的代理(窗口關閉失效),也對npm生效
npm代理,不行

臨時cmd窗口代理,行


到此這篇關于npm安裝時的錯誤排查的方法的文章就介紹到這了,更多相關npm安裝錯誤排查內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
Node.js中Mongodb數(shù)據(jù)庫操作方法(最新推薦)
MongoDB是一種基于分布式文件存儲的NoSQL數(shù)據(jù)庫,它允許存儲和檢索大量結(jié)構化數(shù)據(jù),MongoDB的核心概念包括數(shù)據(jù)庫、集合和文檔,每個集合可以包含多個文檔,每個文檔是一個鍵值對的集合,本文介紹Node.js Mongodb數(shù)據(jù)庫操作方法,感興趣的朋友一起看看吧2024-12-12
利用nodeJs anywhere搭建本地服務器環(huán)境的方法
今天小編就為大家分享一篇利用nodeJs anywhere搭建本地服務器環(huán)境的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-05-05

