I have created a sample react app which I have published to npm repository so I can install them into some other react project. Now I want to publish the same package to Nexus repository so it would be private and I am not able to figure out how to do this. I have tried the following command
npm config set registry "https://my-custom-registry.registry.nodesource.io/"
but when I am trying to publish my npm repo there It giving me an authentication error. what are the other steps I need to perform?
if Nexus 3 use token bearer token, if use nexus 2 you have to use basic authentication
registry=http://.......
always-auth=true
email=mail#mail.test
_auth=ZGV2ZWxvcGVyOmRldmVsb3BlcjEyMw==
this is file .npmrc
i had same error and with this i works like a charm
Related
I upgraded node version to 12.16.2 and npm version to 6.14.4. After that I am not able to run npm install, as I'm getting this error
code E401
npm ERR! Unable to authenticate, need: BASIC realm="Sonatype Nexus Repository Manager"
I even tried deleting node_modules and package-lock.json and running npm install again, but doesn't change anything.
I had similar issue. I resolved it by adding _auth into my ~/.npmrc. See the doc how to encode your nexus credential. I added the encoded credential using npm config set _auth xxx.
You wont be able to see the value using npm config list or npm config get _auth.
In my case, the problem was I've entered another registry address in same Nexus for npm login command.
npm login --registry=http://nexus_url:port/repository/wrong_address
My problem was solved by logging into correct address:
npm login --registry=http://nexus_url:port/repository/correct_address
what worked for me is :
I deleted the .npmrc file under C/users/ folder.
and ran npx vsts-npm-auth -config .npmrc command to create a new file in the users folder
Deleted the .npmrc file under C/users/ folder
npm set registry=http....
npm set _auth=(login:pass in base64):
I found a way out. With this new npm version they are enforcing authentication to access certain packages. We realised we don't need to use authentication for any of the packages we were downloading, hence the auth code we had was unnecessary. So we just removed it and it all worked.
vsts-npm-auth -config .npmrc -F
Is the only solution I found;
Edit: make sure to run npm install -g vsts-npm-auth before
You can remove package-lock.json .. it works with me
I'm run set's command from the post and add in nexus "Active realms" profile "npm Bearer Token Realm". Links: https://help.sonatype.com/repomanager3/system-configuration/access-control/realms
My problem was solved.
I encountered this error when running an npm install that was pulling some dependencies from a non-public registry located on a self-hosted Azure DevOps (AzDo) server.
I had a .npmrc file in the project, and a .npmrc file in my user profile dir with an AzDo personal access token (PAT) that had allowed access previously. The AzDo UI reported my token as still being valid.
PS C:\src\app> npm install
npm ERR! code E401
npm ERR! Unable to authenticate, need: Basic realm="{INTERNAL_REGISTRY_URL}", Negotiate, NTLM
In my case, the solution was to regenerate the AzDo PAT and update the .npmrc found in my user profile directory.
What worked for me was running npm login, then entering my Username, Password, and Email to log in to the registry defined in .npmrc. I then proceeded with npm installing the packages I needed and it worked.
Had the same issue while doing npm i for a private npm registry. Solved it by removing the _authToken parameter from some lines in my .npmrc file in my user's root directory:
Before:
//registry.npm.example.com/:_authToken=NpmToken.XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXX
//npm.artifacts.example.io/:_authToken=NpmToken.XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXX
update-notifier=false
registry=https://npm.artifacts.example.io/
After:
//registry.npm.example.com/
//npm.artifacts.example.io/
update-notifier=false
registry=https://npm.artifacts.example.io/
In my case the Nexus Authentication and project I am using requires Node version: 12.8.1.
I was using node version: 16.13.2
I use NVM to install 12.8.1 with nvm install 12.8.1
Then nvm use 12.8.1
This will now work on my machine and environment.
if the .npmrc file config like this
//registry.npm.example.com/:_auth="base64(username:psw)"
try this
//registry.npm.example.com/:_authToken="base64(username:psw)"
In my case, npmjs expected a Base64 encoded Personal Access Token in the .npmrc file, and I had forgotten to Base64 encode it before pasting it into the user .npmrc file.
You can try downgrading the current node version, 16, to 14.20.0.
My steps to fix this issue.
Earlier I had configured NODE_HOME under "Environment variable".
I removed it.
Only configured the path.
Created a new folder in the "C" drive and pasted the node files.
(System variable)Path = "C:\Node\node-v14.20.0-win-x64"
I had same issue as I had configured my auth through the .npmrc file by adding the below details to it:
_auth=xxx
always-auth=true
email=example#mail.com
The error was:
npm ERR! code E401
npm ERR! Unable to authenticate, need: BASIC realm="Sonatype Nexus Repository Manager"
then got resolved after removing underscore (_) from auth in the .npmrc file:
auth=xxx
always-auth=true
email=example#mail.com
I am having authentication problem when publishing to my private npm registry hosted on my private Nexus.
My Nexus setup is I have npm-proxy, npm-registry (hosted npm with allowRepublish=false), npm-snapshots (hosted npm with allowRepublish=true) and npm-public (group with all other three repositories).
Since I am developing a library, I am using my snapshot repository, so I can redeploy same version constantly (something like snapshot in maven world).
In my library project I have set this option in package.json
"publishConfig": {
"registry": "https://my.nexus.com/repository/npm-snapshots/"
}
Next, I created .npmrc file with following content:
registry=https://my.nexus.com/repository/npm-public/
_auth=RVhBTVBMRQ==
And with this setup I can publish project with no problem. However, what bothers me, is that I have my password (which is just base64 encoded) stored in file, that should be commited, but I can't commit it, due to credentials in it.
I have tried to instead login to npm registry and removed the auth line from .npmrc
npm adduser --registry=https://my.nexus.com/repository/npm-snapshots --always-auth
I got response Logged in as myusername on https://my.nexus.com/repository/npm-snapshots.
However, when I try to run npm publish I get:
npm ERR! code E401
npm ERR! Unable to authenticate, need: BASIC realm="Sonatype Nexus Repository Manager"
npm verb exit [ 1, true ]
npm timing npm Completed in 6867ms
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\XXXX\AppData\Roaming\npm-cache\_logs\2019-07-30T19_31_01_598Z-debug.log
Now in my other project (which is using this library), I simply created .npmrc file with content registry=https://nexus.mjamsek.com/repository/npm-public/ and run command npm adduser --registry=https://my.nexus.com/repository/npm-public --always-auth and I was able to download the published package.
However, the publish still won't work and I don't know why.
EDIT 31.7.2019: On my list of active realms I also have npm Bearer Token Realm
When you do npm login or npm adduser the NPM client creates an authentication token that will be used in future request to the registry. Default NXRM configuration allows only Local Authenticating Realm which doesn't recognise NPM's token. Please make sure you have npm Bearer Token Realm active.
You need a trailing slash on the end of the registry URL passed into npm adduser, otherwise npm will chop off the last segment of the URL, and it won't work.
_auth= replaced with output of btoa('username:userpassword') and it worked for me.
I did use this btoa from chrome as below.
I encountered this problem today, my solution was to delete all registry entry from my npmrc file:
registry=https://my.nexus.com/repository/npm-snapshots/
Idealy delete anything superfluous, back it up before-hand, in my case my file contained only:
strict-ssl=false
Then you can
npm login --registry=https://my.nexus.com/repository/npm-public/ again.
If that's not working, you also bypass npm login with curl, look at this life saving post.
Make sure the _auth token is correct. In my case I changed my system credentials and forgot to generate new _auth token. I was getting the exact same error i.e.
"npm ERR! code E401
npm ERR! Unable to authenticate, need: BASIC realm="Sonatype Nexus Repository Manager"
once i fixed it, the issue was resolved.
For those who are looking for the command to generate _auth. It is:
btoa('username:userpassword')
I had same problem, my solution was to delete my global .npmrc file, and after login npm login.
I had ended with three versions of node on my machine. It turned out that the ones i installed later had their own local .npmrc files in the node_modules folders. They didn't use the global .npmrc even after i removed the local one so i had to copy it.
I was struggling about this problem last two days, finally the solution was to delete .npmrc file from root (user) directory.
When npm tried to login, it used the creds inside this file and ignore your pass login.
I've had a similar issue. I also have our credentials stored in an npmrc file in my user directory. When set up with node16/npm7, I would receive the error
npm ERR! code ENEEDAUTH
npm ERR! need auth This command requires you to be logged in.
npm ERR! need auth You need to authorize this machine using `npm adduser`
If I use nvm to downgrade to node12/npm6, it works. I'd prefer a working solution without downgrading, but for now it lets me move on.
UPDATE:
We finally figured it out (a while ago, but I forgot about this answer). In our .npmrc files in our user directories, we needed to add/change our authorization config entry.
Before:
_auth={base64 encoded username:password}
After:
//{path to private repository}:_auth={base64 encoded username:password}
Just enable anonymous access in the nexus dashboard, it will pull from your private registry.
We are building our project in offline build server. Thus we have to store and maintain all our project dependencies in local network Nexus.
I have created hosted NPM registry in Nexus following this guide. I skipped the proxy and group part. Now I want to upload (and maintain) all the project NPM packages (node_modules) from my local workstation to this repository. I don't see upload button in the Nexus repository settings. How to properly upload and maintain NPM packages in Nexus NPM registry? Can this be done by the Nexus GUI, or do I have to use command line? Note the nexus is disconnected from the internet.
The UI does not handle transitive dependencies.
You can also use the rest API to manage components directly, and upload all your .tgz packages.
POST /v1/components
For instance, to upload the package my-npm-package-0.0.0.tgz to the repository npm-private use the following:
curl -u user:password -X POST "http://localhost:8081/service/rest/v1/components?repository=npm-private" -H "accept: application/json" -H "Content-Type: multipart/form-data" -F "npm.asset=#my-npm-package-0.0.0.tgz;type=application/x-compressed"
The complete live API specs can be found at endpoint /#admin/system/api
The official nexus documentation can be found at https://help.sonatype.com/repomanager3/rest-and-integration-api/components-api
UI upload for npm packages was added in version 3.7.0.
https://help.sonatype.com/display/NXRM3/Uploading+Components
You don't need to upload the node_modules.
You need to create a proxy and a group repository.
Then you can delete the node_modules and package-lock.json in your project and run npm install.
Because your hosted don't have those packages,it will download them from proxy.
Then you can see those packages in the group.
When you run npm install again,it will download form Nexus ,not NPM.
The download speed will be very fast.
Using private registry in connection with IBM Cloud DevOps pipeline, we've got
modules published. In DevOps pipeline also build is possible using following tactic:
#!/bin/bash
export PATH=/opt/IBM/node-v6.7.0/bin:$PATH
npm config set #<scope>:registry <registry-url>
echo "//<registry-url-short>:_authToken=$NPM_TOKEN" >> ~/.npmrc
npm install
This way both public and private modules are found and installed. However, when it comes time to deploy to NodeJS runtime, then 'npm install' is done on platform side.
How can we instruct that with above ?
Another approach is to package your .npmrc file along with your app when you push it. More info here https://github.com/cloudfoundry/nodejs-buildpack/issues/79
The approach here is to create a .npmrc as part of your build stage and add it to the root of your artifact folder. In the next stage when you deploy the app from the artifact folder your npm configuration will be correctly set for per-project config (see https://docs.npmjs.com/files/npmrc) and the npm install that the cf node build-pack performs will work correctly.
One possible way is to have your private modules downloaded in a different directory using the postinstall script in npm. Here is a good explanation on how to achieve this.
https://github.com/pmuellr/bluemix-private-packages
I am trying to use Team City CI to run tests and publish the NPM package to local sinopia repository. I had setup sinopia repository on a server and i can successfully publish npm packages to that repository with npm publish command from my local machine.
But when i try to automate this in Team City , i am getting authentication error as shown below.
Team City Build steps are :
1. npm install
2. npm test
3. npm set #scoped:registry http://{host}:{port}
npm publish
1, 2 steps are running fine. But throwing above error on 3rd step. It definitely has to do with authenticating the Team City server with Sinopia server. Both are installed in different machines.
Is there any way i can pass auth token to sinopia before publishing a package.
NOTE : I can publish NPM packages to Octopus Deploy library and deploy those packages into server automatically.
I solved it as explained below, not sure if there is any better way.
I logged into my DEV Server and from the command prompt i ran the below commands.
npm adduser
typed <username> This must be admin user
typed <password>
typed <email>
User created succesfully. Then
npm config edit
npm configuration will open in notepad. You will see `auth` token there.
You will see something like _authToken=f04c81af-781d-4fc3-a811-4db226950b55.
Then onwards Team city didn't complain about authentication.
NOTE : You have to do this on Team City Agent machine.
Hope this helps.
npm publish --registry //domain.com/repository/:_authToken=${CI_NPM_TOKEN}
or for Nexus
npm publish --registry //domain.com/repository/some-npm-repositury/:_authToken=NpmToken.${CI_NPM_TOKEN}