如何在运行 Node JS 应用程序时解决 NPM 代理问题 [英] How to resolve NPM proxy Issue whilel running Node JS application
问题描述
我已经安装了 Noed JS 和 NPM.我已经从 git 克隆了 repo 并尝试在本地运行该应用程序.但是我在运行应用程序时面临以下代理问题.
<块引用>npm install nodemonnpm 错误!代码未找到npm 错误!错误号 ENOTFOUNDnpm 错误!对 https://registry.npmjs.com/nodemon 的网络请求失败,原因:getaddrinfo ENOTFOUND 28npm 错误!网络 这是一个与网络连接相关的问题.npm 错误!网络 在大多数情况下,您使用的是代理或网络设置不佳.npm 错误!网络npm 错误!网络 如果您使用代理,请确保npm 错误!网络代理"配置设置正确.请参阅:'npm 帮助配置'`
我已检查代理并将其设置为低于网络.
<块引用>ping proxy.internal.domainname.com 有 32 字节的数据:来自<ip address="">的回复:bytes=32 time=2ms TTL=247来自<ip address="">的回复:bytes=32 time=2ms TTL=247来自<ip address="">的回复:bytes=32 time=2ms TTL=247来自<ip address="">的回复:bytes=32 time=2ms TTL=247<ip address=""> 的 Ping 统计信息:数据包:发送 = 4,接收 = 4,丢失 = 0(0% 丢失),大约以毫秒为单位的往返时间:最小值 = 2ms,最大值 = 2ms,平均值 = 2ms
我尝试使用以下命令将代理设置为 https://registry.npmjs.com/nodemon
.
npm 配置设置注册表"http://registry.npmjs.org/
当我在这之后运行 npm install 时,我又遇到了同样的错误.
<块引用>npm --proxy http://registry.npmjs.org/install npmnpm 错误!代码未找到npm 错误!错误号 ENOTFOUNDnpm 错误!对 http://registry.npmjs.org/npm 的网络请求失败,原因:getaddrinfo ENOTFOUND 28npm 错误!网络 这是一个与网络连接相关的问题.npm 错误!网络 在大多数情况下,您使用的是代理或网络设置不佳.npm 错误!网络npm 错误!网络 如果您使用代理,请确保npm 错误!网络代理"配置设置正确.请参阅:'npm 帮助配置'`
我尝试了许多其他来自 google 的解决方法,但仍然面临相同的代理问题.我只是想在本地运行这个应用程序,这样我就可以在部署之前在本地测试我的代码.我是不是在这里遗漏了什么.
以下是我的示例 package.json 文件.
<代码>{"name": "abc",版本":0.0.1","描述": "abc","main": "dist/index.js",引擎": {节点":8.0.0","npm": "5.0.0"},脚本":{"prestart": "npm run -s build","start": "节点 dist/index.js","dev": "nodemon src/index.js --exec \"node -r dotenv/config -r babel-register\"localdev","clean": "rimraf dist && rimraf -p","build": "npm run clean && mkdir -p dist && babel src -s -D -d dist","test": "jest --watch","lint": "esw -w src 测试"},关键词":[表示","巴别","es6","es2015","es2016","es2017",埃斯林特"],"作者": "abc","license": "许可",依赖关系":{"babel-cli": "6.26.0","babel-plugin-transform-object-rest-spread": "6.26.0","babel-preset-env": "1.6.1","cors": "2.8.5","快递": "4.16.4","js-yaml": "3.12.2","mssql": "5.0.0","温斯顿": "3.1.0",温斯顿每日轮换文件":3.5.1"},开发依赖":{"babel-eslint": "7.2.3","babel-jest": "21.0.2","babel-register": "6.24.1","dotenv": "4.0.0","eslint": "4.10.0","eslint-config-airbnb-base": "12.1.0","eslint-plugin-import": "2.8.0","eslint-plugin-jest": "21.0.2","eslint-watch": "3.1.0","nodemon": "1.18.10","rimraf": "2.6.3"},巴别塔":{预设":[["环境",{目标":{节点":当前"}}]],插件":[变换-对象-休息-传播"]},eslintConfig":{"parser": "babel-eslint",插件":[进口",笑话"],解析器选项":{"ecmaVersion": 2017,源类型":模块"},环境":{节点":真,开玩笑":真的},扩展":[eslint:推荐"]}}
<小时>
运行npm config ls
命令返回如下结果:
;cli 配置指标注册=http://registry.npmjs.org/async-each"范围 = ""用户代理 = "npm/6.13.4 node/v12.14.0 win32 x64";用户配置 C:\Users\username\.npmrchttps-proxy = "http://registry.npmjs.org/"https://registry.npmjs.com/nodemon = ""键 = ""registry = "http://registry.npmjs.org/"严格的 ssl = 假;内置配置未定义prefix = "C:\\Users\\username\\AppData\\Roaming\\npm";节点 bin 位置 = C:\Program Files\nodejs\node.exe;cwd = H:\IRB PMX Services\core\src;主页 = C:\用户\用户名;npm config ls -l"显示所有默认值.
<小时>
编辑 2:
我现在已经运行以下命令来删除错误的配置键,即 https://registry.npmjs.com/nodemon = ""
部分:
npm 配置删除 https://registry.npmjs.com/nodemon
并再次运行 npm install
命令.但再次得到代理错误如下:
npm ERR!对 registry.npmjs.org/async-each/@types%2fnode 的网络请求失败,原因:读取 ECONNRESETnpm 错误!网络 这是一个与网络连接相关的问题.npm 错误!网络 在大多数情况下,您使用的是代理或网络设置不佳.npm 错误!网络 npm 错误!网络 如果您使用代理,请确保...
我已经通过以下步骤解决了这个问题:
- 确保您有互联网连接:ping 8.8.8.8
- 确保您的 DNS 解析器正常工作:ping www.google.com
- 确保您可以访问 registry.npmjs.org:ping registry.npmjs.org
- 确保您可以通过 https 连接.
在 npm 命令提示符或 Visual Studio Code 终端中运行以下命令.
npm 配置 rm 代理
npm config rm https-proxy
在浏览器中尝试:https://registry.npmjs.org/
确保您尝试连接到:
<块引用>registry.npmjs.org
而不是:
<块引用>"registry.npmjs.org registry.npmjs.org:443"
使用下面的命令设置注册表.
npm 配置设置注册表 https://registry.npmjs.org/
如果您使用代理访问 Web,那么您还必须配置 npm 才能使用它.使用:
npm config set proxy http://username:password@proxyname:8080
npm config set https-proxy http://username:password@proxyname:8080
设置以上两个值时要记住的要点:
- proxyname 您需要与您的公司网络团队核对.在以上 2 个值中输入该代理网址.
- 如果您的密码包含任何特殊字符,请将其替换为编码字符.在此命令中,您不能提供带有特殊字符的密码.仅替换特殊字符而不是 .(点).<块引用>
例如:密码是:Welcome@12# 那么它就会像 Welcome%4012%23.
https://www.w3schools.com/tags/ref_urlencode.asp
然后尝试运行您的 npm install 命令,它应该可以工作.
I have installed Noed JS and NPM. I have cloned the repo from git and trying to run the app in local. But I am facing below proxy issue while running app.
npm install nodemon npm ERR! code ENOTFOUND npm ERR! errno ENOTFOUND npm ERR! network request to https://registry.npmjs.com/nodemon failed, reason: getaddrinfo ENOTFOUND 28 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'`
I have check with proxy and it is set to below network.
Pinging proxy.internal.domainname.com with 32 bytes of data: Reply from <ip address="">: bytes=32 time=2ms TTL=247 Reply from <ip address="">: bytes=32 time=2ms TTL=247 Reply from <ip address="">: bytes=32 time=2ms TTL=247 Reply from <ip address="">: bytes=32 time=2ms TTL=247 Ping statistics for <ip address="">: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 2ms, Maximum = 2ms, Average = 2ms
I tried to set proxy to https://registry.npmjs.com/nodemon
using below command.
npm config set registry "http://registry.npmjs.org/
When I run npm install after this, again I got the same error.
npm --proxy http://registry.npmjs.org/ install npm npm ERR! code ENOTFOUND npm ERR! errno ENOTFOUND npm ERR! network request to http://registry.npmjs.org/npm failed, reason: getaddrinfo ENOTFOUND 28 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'`
I have tried many other workarounds from google but still facing the same proxy issue. I am just looking to run this app in local so that I can test my code in local before deploying. Am I missing something here.
Below is my sample package.json file.
{
"name": "abc",
"version": "0.0.1",
"description": "abc",
"main": "dist/index.js",
"engines": {
"node": "8.0.0",
"npm": "5.0.0"
},
"scripts": {
"prestart": "npm run -s build",
"start": "node dist/index.js",
"dev": "nodemon src/index.js --exec \"node -r dotenv/config -r babel-register\" localdev",
"clean": "rimraf dist && rimraf -p",
"build": "npm run clean && mkdir -p dist && babel src -s -D -d dist",
"test": "jest --watch",
"lint": "esw -w src test"
},
"keywords": [
"express",
"babel",
"es6",
"es2015",
"es2016",
"es2017",
"eslint"
],
"author": "abc",
"license": "LICENSED",
"dependencies": {
"babel-cli": "6.26.0",
"babel-plugin-transform-object-rest-spread": "6.26.0",
"babel-preset-env": "1.6.1",
"cors": "2.8.5",
"express": "4.16.4",
"js-yaml": "3.12.2",
"mssql": "5.0.0",
"winston": "3.1.0",
"winston-daily-rotate-file": "3.5.1"
},
"devDependencies": {
"babel-eslint": "7.2.3",
"babel-jest": "21.0.2",
"babel-register": "6.24.1",
"dotenv": "4.0.0",
"eslint": "4.10.0",
"eslint-config-airbnb-base": "12.1.0",
"eslint-plugin-import": "2.8.0",
"eslint-plugin-jest": "21.0.2",
"eslint-watch": "3.1.0",
"nodemon": "1.18.10",
"rimraf": "2.6.3"
},
"babel": {
"presets": [
[
"env",
{
"targets": {
"node": "current"
}
}
]
],
"plugins": [
"transform-object-rest-spread"
]
},
"eslintConfig": {
"parser": "babel-eslint",
"plugins": [
"import",
"jest"
],
"parserOptions": {
"ecmaVersion": 2017,
"sourceType": "module"
},
"env": {
"node": true,
"jest": true
},
"extends": [
"eslint:recommended"
]
}
}
Edit:
Running the npm config ls
command returns the following result:
; cli configs metrics-registry = "http://registry.npmjs.org/async-each" scope = "" user-agent = "npm/6.13.4 node/v12.14.0 win32 x64" ; userconfig C:\Users\username\.npmrc https-proxy = "http://registry.npmjs.org/" https://registry.npmjs.com/nodemon = "" key = "" registry = "http://registry.npmjs.org/" strict-ssl = false ; builtin config undefined prefix = "C:\\Users\\username\\AppData\\Roaming\\npm" ; node bin location = C:\Program Files\nodejs\node.exe ; cwd = H:\IRB PMX Services\core\src ; HOME = C:\Users\username ; "npm config ls -l" to show all defaults.
Edit 2:
I have now run the following command to delete the erroneous configuration key, i.e. the https://registry.npmjs.com/nodemon = ""
part:
npm config delete https://registry.npmjs.com/nodemon
and again ran the npm install
command. But again got the proxy error as below:
npm ERR! network request to registry.npmjs.org/async-each/@types%2fnode failed, reason: read ECONNRESET 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 ...
I have resolved this issue with below steps :
- make sure you have internet connection: ping 8.8.8.8
- make sure you have DNS resolver working: ping www.google.com
- make sure you can access registry.npmjs.org: ping registry.npmjs.org
- make sure you can connect via https.
Run below command in npm command prompt or Visual Studio Code terminal.
npm config rm proxy
npm config rm https-proxy
Try in your browser: https://registry.npmjs.org/
Make sure you are trying to connected to:
registry.npmjs.org
and not to:
"registry.npmjs.org registry.npmjs.org:443"
Use below command to set registry.
npm config set registry https://registry.npmjs.org/
If you are using a proxy to access the Web, then you also have to configure npm to use it. Use:
npm config set proxy http://username:password@proxyname:8080
npm config set https-proxy http://username:password@proxyname:8080
Points to remember here while setting above two values :
- proxyname you need to check with your company network team. Enter that proxy URL in above 2 values.
- If your password contains any special character then replace it with Encoded character. In this command you can’t provide a password with special character. Replace only special character not .(dot).
Example: password is : Welcome@12# then it will be like Welcome%4012%23.
https://www.w3schools.com/tags/ref_urlencode.asp
Then try to run your npm install command and it should work.
这篇关于如何在运行 Node JS 应用程序时解决 NPM 代理问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!