npm config set registry https://registry.npmmirror.com/设置完代理之后为什么npm config get proxy还返回false
时间: 2023-12-12 16:02:17 浏览: 1172
设置 registry 并不会自动设置代理。在你执行 `npm config set registry https://registry.npmmirror.com/` 之后,如果你想设置代理,你需要执行类似的命令来设置代理。
你可以尝试执行以下命令来设置代理:
```
npm config set proxy http://your-proxy-server:your-proxy-port
npm config set https-proxy http://your-proxy-server:your-proxy-port
```
将 `your-proxy-server` 替换为你的代理服务器地址,将 `your-proxy-port` 替换为代理服务器端口号。
执行完这两个命令后,再次运行 `npm config get proxy` 应该会返回你设置的代理值。
相关问题
npm config set registry https://npmmirror.com/ 报错
### 解决方案
当执行 `npm config set registry https://npmmirror.com/` 命令时报错,可能是由于几个常见原因引起的。以下是详细的排查和解决方法:
#### 1. 检查 URL 正确性
确保使用的注册表URL是完整的并包含 `/` 结尾。正确的命令应该是:
```bash
npm config set registry https://registry.npmmirror.com/
```
#### 2. 清除缓存
有时旧的包数据可能会引起问题,可以通过清除 npm 缓存来解决问题:
```bash
npm cache clean --force
```
#### 3. 切换回默认源测试
如果仍然存在错误,先切换回到官方 NPM 源进行验证[^2]:
```bash
npm config set registry https://registry.npmjs.org/
```
之后再尝试重新安装依赖项。
#### 4. 设置代理(如果有)
对于某些网络环境下的用户来说,可能需要配置 HTTP 或 HTTPS 代理服务器才能正常使用 NPM 。检查当前是否有误设的代理设置,并将其重置为空[^5]:
```bash
npm config get proxy
npm config get https-proxy
npm config set proxy null
npm config set https-proxy null
```
#### 5. 更新 Node.js 和 NPM 版本
保持开发工具处于最新状态有助于减少兼容性和性能方面的问题。可以从官方网站下载最新的长期支持版本 LTS 来更新 Node.js 及其自带的 NPM 客户端。
#### 6. 查看日志文件
NPM 错误会记录在一个特定的日志文件里,在遇到难以理解或持续存在的问题时查阅这些信息往往能提供额外的帮助。例如,日志路径如下所示[^3]:
```
C:\Users\<用户名>\AppData\Local\npm-cache\_logs\
```
通过以上措施通常能够有效处理大多数与 NPM 注册表有关联的操作失败情况。
npm ERR! code ENOTFOUND npm ERR! syscall getaddrinfo npm ERR! errno ENOTFOUND npm ERR! network request to https://registry.npm.taobao.org/@vue%2fcli failed, reason: getaddrinfo ENOTFOUND proxy-server 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! Log files were not written due to an error writing to the directory: E:\Program Files\node.js\node_cache\_logs npm ERR! You can rerun the command with `--loglevel=verbose` to see the logs in your terminal C:\Users\lhq>npm config set registry http://registry.cnpmjs.org/ C:\Users\lhq>npm install -g @vue/cli npm ERR! code ENOTFOUND npm ERR! syscall getaddrinfo npm ERR! errno ENOTFOUND npm ERR! network request to http://registry.cnpmjs.org/@vue%2fcli failed, reason: getaddrinfo ENOTFOUND proxy-server 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! Log files were not written due to an error writing to the directory: E:\Program Files\node.js\node_cache\_logs npm ERR! You can rerun the command with `--loglevel=verbose` to see the logs in your terminal
这个错误提示表明你的网络连接存在问题,可能是由于代理设置不正确或网络设置不正确导致的。你可以尝试以下解决方案:
1. 检查代理设置:如果你使用了代理服务器,请确保代理配置正确。可以使用以下命令检查代理配置:
```
npm config get proxy
npm config get https-proxy
```
如果返回结果为空或不正确,可以使用以下命令进行设置:
```
npm config set proxy http://your-proxy-server:port
npm config set https-proxy http://your-proxy-server:port
```
将 `your-proxy-server` 替换为你的代理服务器地址,`port` 替换为代理服务器的端口号。
2. 检查网络设置:确保你的网络连接正常,并且没有任何网络层面的问题。可以尝试打开其他网页或使用其他网络连接检查。
3. 更换注册表源:你可以尝试切换到其他的 npm 注册表源。在命令行中运行以下命令切换到 cnpmjs 的源:
```
npm config set registry http://registry.cnpmjs.org/
```
然后再次运行安装命令:
```
npm install -g @vue/cli
```
如果还是无法解决问题,可以尝试使用其他的 npm 注册表源,如淘宝源或官方源。
如果以上方法都没有解决问题,可能需要进一步检查你的网络环境和配置。
阅读全文
相关推荐















