简体   繁体   English

将 npm 包记录/推送到 nexus 时出现 400 个错误请求?

[英]400 bad request when logging/pushing npm package to nexus?

I am trying to use a private npm registry for my nodejs projects and I am using nexus for that matter.我正在尝试为我的 nodejs 项目使用私有npm注册表,并且我正在使用 nexus。 I kept admin user to be used, at least for testing and to guarantee there's no permission issue.我一直使用admin用户,至少用于测试并保证没有权限问题。 However, I can login neither publish using npm login --registry <private-registry-address> and npm publish --registry <private-registry-address> receptively.但是,我无法使用npm login --registry <private-registry-address>npm publish --registry <private-registry-address> I used several methods, first I manually added entries in .npmrc file as follows:我使用了几种方法,首先我手动在.npmrc文件中添加条目,如下所示:

This one is mentioned in Nexus 3 docs: Nexus 3 文档中提到了这一点:

➜  echo "email=$NPM_EMAIL" > $HOME/.npmrc                                       
➜  echo "_auth=$(echo -n "$NPM_USER:$NPM_PASS" | openssl base64)" >> $HOME/.npmrc
➜  echo "always-auth=true" >> $HOME/.npmrc

Then I try to publish using npm publish --registry http://172.17.0.1:8081/repository/npmtest/ , but it just gives me:然后我尝试使用npm publish --registry http://172.17.0.1:8081/repository/npmtest/ ,但它只是给了我:

npm ERR! code E400
npm ERR! 400 Bad Request - PUT http://172.17.0.1:8081/repository/npmtest/mypackage

This one is kind of the official in npm docs:这是 npm 文档中的一种官方文档:

Here, I log in the repo using the credentials I have as follows:在这里,我使用我拥有的凭据登录 repo,如下所示:

➜  npm login --registry http://172.17.0.1:8081/repository/npmtest/

and enter my login creds:并输入我的登录凭据:

Username: admin
Password: 
Email: (this IS public) admin@example.org

But unfortunately, it gives me the same exact error:但不幸的是,它给了我同样的错误:

npm ERR! code E400
npm ERR! 400 Bad Request - PUT http://localhost:8081/repository/npmtest/-/user/org.couchdb.user:admin

I have added npm Bearer Token Realm in Nexus as I saw in many discussions and it didn't make a difference as well.正如我在许多讨论中看到的那样,我在 Nexus 中添加了npm Bearer Token Realm并且它也没有什么不同。

I have tried to use another repo verdaccio and it worked normally, that's why I am pretty sure this is a nexus issue.我尝试使用另一个 repo verdaccio并且它正常工作,这就是为什么我很确定这是一个关系问题。

Note: I am using all repo managers (Nexus and verdaccio) as docker containers, anyway this should not be an issue.注意:我使用所有 repo 管理器(Nexus 和 verdaccio)作为 docker 容器,无论如何这应该不是问题。

I am running npm version 6.10我正在运行npm 6.10

What could be a solution here for nexus to work?这里有什么解决方案可以让 nexus 工作?

 { ..., "publishConfig": { "registry": "<linkToNexusRepo>" } }

Resolve the issue for me by adding this snipped in my package.json .通过在我的package.json添加这个片段来解决我的问题。

The problem kinda stupid and my fault, but I would like to leave the question since it has useful code that might help someone else. 这个问题有点愚蠢,是我的错,但是我想离开这个问题,因为它包含有用的代码,可能会对其他人有所帮助。 Simply, repo type was incorrect. 简而言之,回购类型不正确。 I have mistakenly chosen the wrong type instead of choosing npm. 我错误地选择了错误的类型,而不是选择npm。

Make sure you have selected the correct format and type for the repository.确保您为存储库选择了正确的格式和类型。 In my case I accidentally created the npm repository with the incorrect format.就我而言,我不小心创建了格式不正确的 npm 存储库。

I created a Format: nuget instead of Format: npm .我创建了一个Format: nuget而不是Format: npm

You can see the format when you select the repository in the Nexus dashboard.在 Nexus 仪表板中选择存储库时,您可以看到格式。

Make sure, we have to keep same npmrc line of code at both place确保我们必须在两个地方都保留相同的 npmrc 代码行

-- $HOME/.npmrc
-- Project .npmrc at root level.
registry=http://172.17.0.1:8081/repository/npmtest/mypackage/npm/registry/

always-auth=true

; begin auth token // remove in the case of $HOME/.npmrc
//repository/npmtest/mypackage/npm/registry/:username=****
//repository/npmtest/mypackage/npm/registry/:_password=${NPM_TOKEN}
//repository/npmtest/mypackage/npm/registry/:email=*****
//repository/npmtest/mypackage/npm/:username=****
//repository/npmtest/mypackage/npm/:_password=${NPM_TOKEN}
//repository/npmtest/mypackage/npm/:email=*****

; end auth token // remove in the case of $HOME/.npmrc

It will sure work ;)它肯定会工作;)

You should either choose your local registry in your command explicitly, or do a one time config like below:您应该在命令中明确选择本地注册表,或者执行如下一次性配置:

npm config set registry http://localhost:port

Example for explicit registry without using above command:不使用上述命令的显式注册表示例:

npm adduser --registry http://localhost:port

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 安装webpack npm软件包时收到400错误的请求错误 - getting 400 bad request error while installing webpack npm package npm 和 package.json _ npm 中的所有者存储库出现问题 ERR! 400 错误请求(npm 发布) - problem with owner repositories in npm and package.json _ npm ERR! 400 Bad Request (npm publish) 从 NodeJS 登录 Keycloak:400 错误请求 - Logging into Keycloak from NodeJS: 400 Bad Request Bitbucket API NodeJS package 创建存储库时出现错误的请求 400 错误 - Bitbucket API NodeJS package Bad Request 400 error when creating a repository 快速单击时 POST 400 错误请求 - POST 400 bad request when clicking fast 通过 fetch 发布时出现 400 错误请求 - 400 Bad Request when POSTing via fetch 我收到 npm ERR: 400 Bad Request - GET https.//artifactory.devops."************"/artifactory/api/npm/npm/npm - I'm getting npm ERR! 400 Bad Request - GET https://artifactory.devops."**********"/artifactory/api/npm/npm/npm 错误:400错误的请求 - Error:400 Bad Request Sails当发生错误的request / 400错误时,如何重定向页面? - Sails How to redirect page when bad request/400 error occurs? 发布到API时第二次出现400(错误请求) - 400 (Bad Request) Second Time When Posting to API
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM