Badr
Badr

Reputation: 733

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. I kept admin user to be used, at least for testing and to guarantee there's no permission issue. However, I can login neither publish using npm login --registry <private-registry-address> and npm publish --registry <private-registry-address> receptively. I used several methods, first I manually added entries in .npmrc file as follows:

This one is mentioned in Nexus 3 docs:

➜  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 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:

Here, I log in the repo using the credentials I have as follows:

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

and enter my login creds:

Username: admin
Password: 
Email: (this IS public) [email protected]

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.

I have tried to use another repo verdaccio and it worked normally, that's why I am pretty sure this is a nexus issue.

Note: I am using all repo managers (Nexus and verdaccio) as docker containers, anyway this should not be an issue.

I am running npm version 6.10

What could be a solution here for nexus to work?

Upvotes: 9

Views: 27580

Answers (4)

shubham
shubham

Reputation: 9

Make sure, we have to keep same npmrc line of code at both place

  • $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 surely work ;)

Upvotes: 0

dvanrensburg
dvanrensburg

Reputation: 1441

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.

I created a Format: nuget instead of Format: npm.

You can see the format when you select the repository in the Nexus dashboard.

Upvotes: 0

user13747357
user13747357

Reputation:

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

Upvotes: -2

Pankaj Gamnani
Pankaj Gamnani

Reputation: 59

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

Resolve the issue for me by adding this snipped in my package.json.

Upvotes: 4

Related Questions