情况:用npm安装element-plus失败
问题:
npm ERR! code ETIMEDOUT
npm ERR! syscall connect
npm ERR! errno ETIMEDOUT
npm ERR! network request to https://registry.npmjs.org/element-plus failed, reason: connect ETIMEDOUT 104.16.0.35:443
npm ERR! network This is a problem related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly. See: 'npm help config'
npm ERR! A complete log of this run can be found in:
npm ERR! D:\node\node_cache\_logs\2024-02-28T09_41_02_282Z-debug-0.log
解决方法:
-
设置或取消代理:如果你在使用代理服务器,你需要确保 npm 的 ‘proxy’ 配置已经正确设置2。你可以使用以下命令来设置代理:
npm config set proxy http://server:port npm config set https-proxy http://server:port
npm config delete proxy npm config delete http-proxy npm config delete https-proxy
-
更改 npm 的 registry 设置:你可以尝试将 npm 的 registry 设置从 https 改为 http3:
npm config set registry http://registry.npmjs.org/
-
关闭 SSL:虽然这个方法可能会带来安全风险,但是你可以尝试关闭 SSL 来解决这个问题3:
npm config set strict-ssl false
-
清理 npm 缓存:你可以尝试清理 npm 的缓存,然后再次尝试安装4:
npm cache clean --force npm install