I'm trying to access a private npm registry that is hosted in a remote server. I have to access it using username and password. There is no proxy on my side.
But, the username and password which I use, have URL unsafe characters. I've tried adduser
, npmjs
, scl
but I'm unable to configure the credentials :
npm WARN Name may not contain non-url-safe chars
I've tried to set NPM_USER
and NPM_PASS
directly from command line. I'm able to set the former but the later fails. Even if I use a simple password and try :
npm login
It fails with the same error since NPM_USER
has a @
I'm using npmrc
to switch between public and private registries. I want to avoid tools like Nexus/JFrog
.
npm version - 4.0.5 and OS is Windows 7
What am I missing here?
With npm private packages, you can use the npm registry to host code that is only visible to you and chosen collaborators, allowing you to manage and use private code alongside public code in your projects. Private packages always have a scope, and scoped packages are private by default.
The npmrc manages the npm config files. The config setting for npm is gotten from the command line, environment variables and the npmrc files. You can use the npm config command to update and edit the contents of the user and global npmrc files.
So to recap, your problem is that your private registry uses email addresses for user names, which is not currently supported by the npm command line tools. You need a way to provide your user name without running npm adduser
or npm login
. I don't know which registry you are using, but I had the same problem with Inedo's Proget.
EDIT: I have the same problem in March 2021, with Azure Artifacts in Azure DevOps, because the npm command-line tools still don't allow @
in usernames, and also the vsts-npm-auth
command-line tool does not work on Linux or Mac. I have also had the same problem with Artifactory.
If you're using a private registry and you are using scopes to separate the different registries, you can create an .npmrc
file that looks like this:
#Settings for @SCOPENAME @SCOPENAME:registry=https://DOMAIN/FEED/ //DOMAIN/FEED/:username=USER@DOMAIN //DOMAIN/FEED/:_password=BASE64(PASSWORD) //DOMAIN/FEED/:email=EMAIL_ADDRESS //DOMAIN/FEED/:always-auth=true #Settings for @OTHERSCOPENAME @OTHERSCOPENAME:registry=...
This next bit might be important, but it depends on your registry's preferred feed urls: I couldn't get this to work properly without the trailing /
so take care to try both with and without it.
An easy way to get the base64 encoding of your password is to run:
echo -n 'PASSWORD' | base64
EDIT: For some registries, like Azure Artifacts, you need to use a personal access token instead of your normal password. Look up the instructions for your registry about how to create a token.
EDIT: It's also possible to have the .npmrc
file without scopes, if you are only using one registry:
# Global settings registry=https://DOMAIN/FEED/ //DOMAIN/FEED/:username=USER@DOMAIN //DOMAIN/FEED/:_password=BASE64(PASSWORD) //DOMAIN/FEED/:email=EMAIL_ADDRESS //DOMAIN/FEED/:always-auth=true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With