安陽做網(wǎng)站的公司流量寶
前言
最近在給一個基于 Electron 的開源項目做貢獻,需要去安裝一些 npm 庫,由于眾所周知的原因,經(jīng)常會出現(xiàn)報錯:
npm ERR! path D:\Projects\project\node_modules\electron
npm ERR! command failed
npm ERR! command C:\Windows\system32\cmd.exe /d /s /c node install.js
npm ERR! RequestError: socket hang up
npm ERR! at ClientRequest.<anonymous> (D:\Projects\project\node_modules\@electron\get\node_modules\got\dist\source\core\index.js:970:111)
npm ERR! at Object.onceWrapper (node:events:632:26)
npm ERR! at ClientRequest.emit (node:events:529:35)
npm ERR! at origin.emit (D:\Projects\project\node_modules\@szmarczak\http-timer\dist\source\index.js:43:20)
npm ERR! at TLSSocket.socketOnEnd (node:_http_client:525:9)
npm ERR! at TLSSocket.emit (node:events:529:35)
npm ERR! at endReadableNT (node:internal/streams/readable:1368:12)
npm ERR! at connResetException (node:internal/errors:720:14)
npm ERR! at TLSSocket.socketOnEnd (node:_http_client:525:23)
npm ERR! at TLSSocket.emit (node:events:529:35)
npm ERR! at endReadableNT (node:internal/streams/readable:1368:12)
npm ERR! at process.processTicksAndRejections (node:internal/process/task_queues:82:21)npm ERR! A complete log of this run can be found in: C:\Users\xxx\AppData\Local\npm-cache\_logs\2023-12-17T04_00_17_970Z-debug-0.log
這是因為網(wǎng)絡(luò)連接的問題而無法安裝,嘗試了國內(nèi)鏡像但是也會出一些奇怪的問題。下面假設(shè)你有一個合規(guī)的代理。
正文
npm config set proxy=http://127.0.0.1:7891
npm config set https-proxy=http://127.0.0.1:7891
npm install vue # 安裝需要的包
但是有些情況下還是會遇到神奇的問題??梢試L試下面的命令更新 npm 解決。
npm install npm -
PS:從參考來源那里拷貝的代碼在命令尾部包括了一個`-`。我在測試中使用這個帶 `-` 的命令,并且后面順利安裝了。但是目前并不明確這個 `-` 的意義,簡單瀏覽了官方文檔沒有看到類似的寫法。(LLM表示這個可能就是表示這個命令結(jié)束用的。也有LLM說這個代表 @latest,但是同樣沒有在文檔中找到相關(guān)描述,不排除幻覺可能,但是這個事情不重要,蹲大神賜教了)
Reference
解決各種 npm install 報錯問題_coc.nvim 配置 error getaddrinfo eai_again re-CSDN博客