Import a private repository from linux - npm

The code below works fine with Windows with the command mpm i.
"dependencies": {
"my-pack": "git+https://myprivategit.com/my/repo#v0.1.0"
},
A credential form standard of windows is open, and the login and password is passed.
But on Linux an authetication error is returned.
npm install
npm ERR! Error while executing:
npm ERR! /usr/bin/git ls-remote -h -t https://myprivategit.com/my/repo
npm ERR!
npm ERR! remote: HTTP Basic: Access denied
npm ERR! fatal: Authentication failed for 'https://myprivategit.com/my/repo.git/'
npm ERR!
npm ERR! exited with error code: 128

Looks like you need to add your credentials, can you try the following:
Generate an access token for the repository you wish to npm install from. For example, go here to create an access token.
Prefix your GIT Repo within your package.json to use the access token generated from step 1:
"dependencies": {
"my-pack": "git+https://<token>:x-oauth-basic#github.com/<user>/myprivategit.com/my/repo#v0.1.0"
},
or:
Create a .netrc within your home directory and give it the necessary credentials to login:
touch ~/.netrc
.netrc:
machine github.com login <token>
then just leave the url to your private repo as is within your .package.json

What worked for me was to do the npm install together with my ssh key stored in .ssh.
npm install git+ssh://git#your_git_server.com:your_username/your_private_repo_name.git
I followed this tutorial.

Related

Could not resolve hostname github.com: Name or service not known

Started receiving the error; Could not resolve hostname github.com: Name or service not known after updating our npm version from 6.14.14 to 8.1.2 when trying to run npm publish against our private package to our private registry.
Our package.json is configured with "private": true and we have also configured our private registry in a local .npmrc file on the build server.
> npm publish dist/{{project}}
npm ERR! code 128
npm ERR! An unknown git error occurred
npm ERR! command git --no-replace-objects ls-remote ssh://git#github.com/dist/{{project}}.git
npm ERR! ssh: Could not resolve hostname github.com: Name or service not known
npm ERR! fatal: Could not read from remote repository.
npm ERR!
npm ERR! Please make sure you have the correct access rights
npm ERR! and the repository exists.
Why is this updated version of npm trying to publish to github.com?
Switching the build agent target back to the 6.14.14 install does not try to publish out to github.com and successfully publishes it to our private registry.

Publish npm package to gitlab registry

I am trying to publish a package to a private Gitlab npm registry. I am following gitlab's docs on how to do this, but something isn't working right.
First, I created a personal access token with all access. Then, in my terminal, as per their docs, I set
npm config set #myproject/my_package http://gitlab.com/api/v4/projects/myproject/my_package/packages/npm/
npm config set -- http://gitlab.com/api/v4/projects/myproject/my_package/packages/npm/:_authToken "<my_token>"
Though there is no output from these commands, so I'm not really sure what its doing or if its working as intended.
Next, in my package.json, I set the name and publishConfig to what you would expect for a scoped package:
{
"name": "#myproject/my_package",
"publishConfig": {
"access": "restricted",
"#myproject/my_package": "https://gitlab.com/af56/myproject/my_package/packages/npm/"
}
}
I then run npm publish. I see that the package is being built, but then I get an error
npm ERR! code ENEEDAUTH
npm ERR! need auth This command requires you to be logged in to https://registry.npmjs.org/npm ERR!
need auth You need to authorize this machine using `npm adduser`
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\me\AppData\Local\npm-cache\_logs\2022-11-09T00_00_38_418Z-debug-0.log
I don't understand why npm is trying to reach npmjs when I configured it to use gitlab as the registery, both through the command line, and in the package.json. I've published packages to npmjs before, but never to gitlab registry, so I'm not sure what steps I'm missing / doing wrong.

Npm install does not installs secure package though i do npm login followed by npm install commands

Even after logged in using npm login command successfully i get the below error
npm whoami
npm ERR! code E401
npm ERR! 401 Unauthorized - GET https://registry.npmjs.org/-/whoami
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/bharathkumar/.npm/_logs/2021-09-09T08_42_29_365Z-debug.log
Try removing contents/remove file .npmrc in the project folder or the user's home folder

install #sencha/ext-react-modern for free trial of ExtReact failed

After requesting for the free trial version of ExtReact at https://www.sencha.com/products/extreact/evaluate/ an email providing a username and password was sent to my inbox.
Next, I opened my command line interface and tried to log in via command:
npm login --registry=https://npm.sencha.com --scope=#sencha
After inputting my username and password provided from the email. The output logged was this:
Logged in as username..gmail.com to scope #sencha on https://npm.sencha.com/.
Next I ran this npm command to install #sencha/ext-react-modern
npm install #sencha/ext-react-modern
Every time I try to npm install an error is thrown on the cmd line display:
npm ERR! code E403
npm ERR! 403 403 Forbidden - GET https://npm.sencha.com/#sencha%2fext-react-classic - unregistered users are not allowed to access package #sencha/ext-react-classic
npm ERR! 403 In most cases, you or one of your dependencies are requesting
npm ERR! 403 a package version that is forbidden by your security policy.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\joeChicago\AppData\Roaming\npm-cache\_logs\2020-06-24T12_19_08_309Z-debug.log
Please, I will really appreciate any help you can provide. Thanks alot!
Check the link:- ExtReact - npm ERR! 403 403 Forbidden
https://docs.sencha.com/extwebcomponents/7.0.0/guides/open_tooling_npm/npm_help.html
Windows (Command Prompt)
Run del %HOMEPATH%.npmrc - removes the stored npm repository credentials. This location may be different on your system.(or manually delete this file finding it in local computer)
Run npm cache clean --force or rmdir /s /q %HOMEPATH%\AppData\Roaming\npm - clean the npm packages.
Run rmdir /s /q %HOMEPATH%\AppData\Roaming\npm-cache - clean the npm cache by removing it.
Run npm login --registry=https://npm.sencha.com --scope=#sencha - log back into the repository.
Run npm install -g #sencha/ext-gen or npm install -g #sencha/ext-react-gen

Not able to setup a local npm repo

I wrote a library and I want to test that people can import it from npm and use it as expected. Towards this I set up a local NPM repo like
npm install -g local-npm
npm set registry http://127.0.0.1:5080
local-npm
This started a local repository on my computer. Now I went to my library project and I did
npm publish
but I get an error
npm ERR! code ENEEDAUTH
npm ERR! need auth auth required for publishing
npm ERR! need auth You need to authorize this machine using `npm adduser`
I did
npm adduser
but I get an error
npm adduser
Username: foo
Password:
Email: (this IS public) foo#bar.com
npm ERR! code EAUTHIP
npm ERR! Unable to authenticate, need: Basic
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/.npm/_logs/2018-04-07T17_46_18_631Z-debug.log
For this local repo. I don't want any users etc because this is only for testing. I want to be able to straight publish to this without any credentials or users. is that possible?
Also, another question is that now that I have setup a local npm and I do a npm i react -D in my project the installation would fail because this repository doesn't contain react. So is it possible that when someone does npm i react -D it still goes to the original NPM repository when when I do npm i foo-lib -D only then it comes to my repository as a fallback because the original npm repository doesn't contain my foo-lib it was only published to this local repository.
Edit: I tried npm publish --registry http://127.0.0.1:5800 and I got the following error
0/bin/npm" "publish" "--registry" "http://127.0.0.1:5080"
23 verbose node v9.5.0
24 verbose npm v5.7.1
25 error code ENEEDAUTH
26 error need auth auth required for publishing
27 error need auth You need to authorize this machine using `npm adduser`
28 verbose exit [ 1, true ]
So it won't let me create a user and it won't let me publish without a user.
Edit2:: I tried the other way round as well.
First run local-npm now when the server starts up
from another window do
npm set registry http://127.0.0.1:5080
npm publish --registry http://127.0.0.1:5080
npm publish
everything results in
~/IdeaProjects/t > npm publish --registry http://127.0.0.1:5080
npm ERR! code ENEEDAUTH
npm ERR! need auth auth required for publishing
npm ERR! need auth You need to authorize this machine using `npm adduser`
npm ERR! A complete log of this run can be found in:
npm ERR! /Users//.npm/_logs/2018-04-07T18_32_53_815Z-debug.log
~/IdeaProjects/t > npm adduser
Username: foo
Password:
Email: (this IS public) foo#bar.com
npm ERR! code EAUTHIP
npm ERR! Unable to authenticate, need: Basic
npm ERR! A complete log of this run can be found in:
npm ERR! /Users//.npm/_logs/2018-04-07T18_33_25_737Z-debug.log
file contents
19 verbose argv "/Users/a/.nvm/versions/node/v9.5.0/bin/node" "/Users/a/.nvm/versions/node/v9.5.0/bin/npm" "adduser"
20 verbose node v9.5.0
21 verbose npm v5.7.1
22 error code EAUTHIP
23 error Unable to authenticate, need: Basic
Try this:
npm publish --registry http://127.0.0.1:5080
https://docs.npmjs.com/misc/registry#can-i-run-my-own-private-registry