使用Nexus https npm注册表代理时,应如何在.npmrc中设置_auth?
上下文使用Nexus https npm注册表代理时,应如何在.npmrc中设置_auth?,npm,nexus,npm-install,Npm,Nexus,Npm Install,上下文 我的.npmrc文件似乎已正确读取(通过命令行和Maven build中的npm config ls-l进行检查) 运行npm的机器无法直接连接到网络,它只能连接到Nexus npm注册表url。因此,未设置代理属性proxy和https proxy 由于对Nexus的访问受到限制,我从Nexus内部生成了一个访问令牌 Nexus安全令牌由用户名和密码组成,用户名和密码都包含/等字符,这些字符通常必须是“url编码”的 正如所料,使用此配置,在运行npm install时,不会检测到任何
.npmrc
文件似乎已正确读取(通过命令行和Maven build中的npm config ls-l
进行检查)npm
的机器无法直接连接到网络,它只能连接到Nexus npm注册表url。因此,未设置代理属性proxy
和https proxy
/
等字符,这些字符通常必须是“url编码”的npm install
时,不会检测到任何代理json
文件,也可以使用web浏览器下载tgz
文件)注册表设置为http://registry.npmjs.org/和注释\u auth
,电子邮件
,始终进行身份验证
,严格的ssl
属性,并添加代理
和https代理
配置,npm安装
按预期工作(但我无法在目标环境中执行此操作)
.npmrc
的内容
; Nexus proxy registry pointing to http://registry.npmjs.org/
registry = https://<host>/nexus/content/repositories/npmjs-registry/
; base64 encoded authentication token
_auth = <see question below>
; required by Nexus
email = <valid email>
; force auth to be used for GET requests
always-auth = true
; we don't want to put certificates in .npmrc
strict-ssl = false
loglevel = silly
当获取此请求需要身份验证凭据时
错误我有以下堆栈跟踪:
http request GET https://<host>/nexus/content/repositories/npmjs-registry/fsevents
sill fetchPackageMetaData Error: socket hang up
sill fetchPackageMetaData at TLSSocket.onHangUp (_tls_wrap.js:1035:19)
sill fetchPackageMetaData at TLSSocket.g (events.js:260:16)
sill fetchPackageMetaData at emitNone (events.js:72:20)
sill fetchPackageMetaData at TLSSocket.emit (events.js:166:7)
sill fetchPackageMetaData at endReadableNT (_stream_readable.js:905:12)
sill fetchPackageMetaData at doNTCallback2 (node.js:441:9)
sill fetchPackageMetaData at process._tickCallback (node.js:355:17)
sill fetchPackageMetaData error for fsevents@^1.0.0 { [Error: socket hang up] code: 'ECONNRESET' }
WARN install Couldn't install optional dependency: socket hang up
verb install Error: socket hang up
verb install at TLSSocket.onHangUp (_tls_wrap.js:1035:19)
verb install at TLSSocket.g (events.js:260:16)
verb install at emitNone (events.js:72:20)
verb install at TLSSocket.emit (events.js:166:7)
verb install at endReadableNT (_stream_readable.js:905:12)
verb install at doNTCallback2 (node.js:441:9)
verb install at process._tickCallback (node.js:355:17)
npm sill fetchPackageMetaData Error: This request requires auth credentials. Run `npm login` and repeat the request.
npm sill fetchPackageMetaData at CachingRegistryClient.authify (<root>\ui\target\node\node_modules\npm\node_modules\npm-registry-client\lib\authify.js:17:14)
npm sill fetchPackageMetaData at CachingRegistryClient.makeRequest (<root>\ui\target\node\node_modules\npm\node_modules\npm-registry-client\lib\request.js:103:17)
npm sill fetchPackageMetaData at <root>\ui\target\node\node_modules\npm\node_modules\npm-registry-client\lib\request.js:66:17
npm sill fetchPackageMetaData at RetryOperation._fn (<root>\ui\target\node\node_modules\npm\node_modules\npm-registry-client\lib\attempt.js:18:5)
npm sill fetchPackageMetaData at null._onTimeout (<root>\ui\target\node\node_modules\npm\node_modules\retry\lib\retry_operation.js:49:10)
npm sill fetchPackageMetaData at Timer.listOnTimeout (timers.js:92:15)
npm sill fetchPackageMetaData error for fsevents@^1.0.0 [Error: This request requires auth credentials. Run `npm login` and repeat the request.]
npm WARN install Couldn't install optional dependency: This request requires auth credentials. Run `npm login` and repeat the request.
npm verb install Error: This request requires auth credentials. Run `npm login` and repeat the request.
npm verb install at CachingRegistryClient.authify (<root>\ui\target\node\node_modules\npm\node_modules\npm-registry-client\lib\authify.js:17:14)
npm verb install at CachingRegistryClient.makeRequest (<root>\ui\target\node\node_modules\npm\node_modules\npm-registry-client\lib\request.js:103:17)
npm verb install at <root>\ui\target\node\node_modules\npm\node_modules\npm-registry-client\lib\request.js:66:17
npm verb install at RetryOperation._fn (<root>\ui\target\node\node_modules\npm\node_modules\npm-registry-client\lib\attempt.js:18:5)
npm verb install at null._onTimeout (<root>\ui\target\node\node_modules\npm\node_modules\retry\lib\retry_operation.js:49:10)
npm verb install at Timer.listOnTimeout (timers.js:92:15)
npm sill fetchPackageMetaData错误:此请求需要身份验证凭据。请运行“npm login”,然后重复该请求。
npm sill fetchPackageMetaData位于CachingRegistryClient.autify(\ui\target\node\node\u modules\npm\node\u modules\npm registry client\lib\autify.js:17:14)
npm sill fetchPackageMetaData位于CachingRegistryClient.makeRequest(\ui\target\node\node\u modules\npm\node\u modules\npm registry client\lib\request.js:103:17)
npm sill fetchPackageMetaData位于\ui\target\node\node\u modules\npm\node\u modules\npm registry client\lib\request.js:66:17
npm sill在RetryOperation时获取PackageMetadata.\u fn(\ui\target\node\node\u modules\npm\node\u modules\npm registry client\lib\trust.js:18:5)
npm sill fetchPackageMetaData为空。\u onTimeout(\ui\target\node\node\u modules\npm\node\u modules\retry\lib\retry\u operation.js:49:10)
npm sill fetchPackageMetaData位于Timer.listOnTimeout(timers.js:92:15)
fsevents@^1.0.0的npm sill fetchPackageMetaData错误[错误:此请求需要身份验证凭据。请运行'npm login'并重复该请求。]
npm WARN install无法安装可选依赖项:此请求需要身份验证凭据。请运行“npm login”,然后重复该请求。
npm谓词安装错误:此请求需要身份验证凭据。请运行“npm login”,然后重复该请求。
npm谓词安装在CachingRegistryClient.autify(\ui\target\node\node\u modules\npm\node\u modules\npm registry client\lib\autify.js:17:14)
npm谓词安装在CachingRegistryClient.makeRequest(\ui\target\node\node\u modules\npm\node\u modules\npm registry client\lib\request.js:103:17)
npm谓词安装在\ui\target\node\node\u modules\npm\node\u modules\npm registry client\lib\request.js:66:17
在重试操作时安装npm谓词。\ fn(\ui\target\node\node\u modules\npm\node\u modules\npm registry client\lib\trust.js:18:5)
npm谓词安装为空。\u onTimeout(\ui\target\node\node\u modules\npm\node\u modules\retry\lib\retry\u operation.js:49:10)
npm谓词安装在Timer.listOnTimeout(timers.js:92:15)
提前感谢。在查看了注册表客户端后,我找到了答案,在这里。我发布它,因为它可能会帮助其他人:
base64Encode(<username>:<password>)
base64Encode(:)
顺便说一句,有一个URL编码,但负责它的是autify.js
我面临的“套接字挂起”问题是由于这样一个事实:如果在Windows配置中设置了代理,那么当从CLI(而不是从Maven构建)启动
npm
时,所有的“``.npmrc``代理设置似乎都会被忽略,而本机代理排除(对于公司URL)被npm忽略。我将打开一张罚单报告这种奇怪的行为。我不知道Nexus,但我们使用artifactory作为npm repo,在那里我可以通过调用base64encode(用户名:encryptedPassword)
创建我的身份验证令牌,其中encryptedPassword
是我从个人artifactory配置文件中获得的
也许这会有帮助。
我刚刚编写了一个包装器,将凭据存储在您的系统密钥链中并动态提供。请检查:如果您有授权令牌,则不应使用用户名:密码。 我建议你:
- 删除~/.npmrc或重命名它
- 确保您的环境设置(如$NPM_CONFIG_*)未设置
- 使用以下命令验证电子邮件和其他设置是否未设置:
npm config list
- 使用:
npm login--registry登录到npm=https://nexus.whatever.registry/respository/npm-whatever-group/
- 一旦您登录-您已登录。npm应在~/.npmrc中为其生成一个令牌。它将如下所示:
//nexus.whatever.registry/respository/npm whater group/:_authToken=NpmToken.YOUR-LOVELY-TOKEN-IN-HEX
//nexus.whatever.registry/respository/npm whater group/:_authToken=NpmToken.YOUR-LOVELY-TOKEN-IN-HEX
电子邮件=
始终auth=true
注册表=https://nexus.whatever.registry/respository/npm-whatever-group/
- 添加环境变量(也添加到CI/CD管线)
$NODE_EXTRA_CA_证书指向/home/where/is/your/cert.pem
$ echo -n 'username:password' | openssl base64
Before you run npm login, please follow the instructions below : 1) Create an ~/.npmrc file with the following contents: registry=https://example.com/repository/npm-group/ email=username@example.com always-auth=true //example.com/repository/npm-group/:_authToken= 2) run `npm login` # npm login Username: firstname.lastname Password: Email: (this IS public) firstname.lastname@example.com Logged in as firstname,lastname on https://example.com/repository/npm-group/. Use the same password you use to login to example.com