Running 'npm install' causes a 'npm ERR! code E401' - node.js

I'm trying to get a co-worker set up so that she can run 'npm install' I'm able to run it fine on my machine.
When she runs the command, it starts and appears to be running successfully for several minutes - and then dies at the very end with:
npm ERR! code E401
npm ERR! Unable to authenticate, need: BASIC realm="Sonatype Nexus Repository Manager"
I know that she has a recent version of nodejs installed.
I also know that she has access to our nexus repository and should have all the correct permissions. I'm also a little surprised that it appears to be running fine and then dies right at the end. I would think if there was an authentication error she would get it right away.
Any suggestions?
Thanks

Check: https://blog.npmjs.org/post/180599338975/401-scoped-packages
"How to fix the issue First, you can verify your token by running npm
whoami. If it’s invalid or you got the 401 previously mentioned, run
npm login to create a new token and you are good to go." npm

Related

Lerna giving EPERM errors

when trying to run this specific command:
lerna run -parallel lint
I consistently get this error:
EPERM: operation not permitted, scandir 'C:/Users/USER1/Application Data'
This is for a simple react app and npm install, start, etc all work as intended. It is only this command that does not work.
I have already tried many different solutions including:
npm clean cache -force
Run as administrator
Change permissions for both npm, project folder, AppData/Roaming to allow anyone to have full control
Delete all node modules and reinstall using "npm install -force", "npm cache verify", or "npm install --no-bin-links"
Disable anti-virus or Windows defender
Make sure no other node servers or scripts are running
Run on PowerShell, command prompt, VSCode, etc (tried pretty much every single CLI)
Install latest version of npm
Probably some others that I have since forgotten due to trying so many solutions
Also if the problem is actually related to npm and not lerna, then unfortunately I also cannot swap to using Yarn, as this is apart of a school project where a pre-commit script runs the lerna command and I cannot change it.
Please if anyone has encountered this issue, let me know.

Authentication error on publishing to private NPM repository on Nexus

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.

npm publish / npm install - auth token invalidation

I think NPM is struggling with security a bit today, when I run npm install on a local project, I get:
'npm WARN notice Due to a recent security incident, all user tokens
have been invalidated. Please see
https://status.npmjs.org/incidents/dn7c1fgrr7ng for more details. To
generate a new token, visit https://www.npmjs.com/settings/~/tokens or
run "npm login"
I signed in again with npm login, but I get the same error. Does anyone know of a workaround?
I get same warning even after the new login:
I get that if the package name is incorrect, on top of the 404 error.
If you need to be logged in just log back in.
If you don't need to be logged in just check that you have the correct package name.
In my case react-native-create-app didn't exist.. After adding the correct name: create-react-native-app it worked.
Make sure you have your npmrc file set up ok.
https://docs.npmjs.com/files/npmrc
Steps to follow:
Run npm login
Enter your
Username
Password
Email address
Note: if you don't have this credentials, you have to sign up at https://www.npmjs.com/signup
Run npm install bootstrap --save
This should work.
After performing npm login try to reopen CLI you are using in order to run npm commands. It worked for me

Error while using create-react-app - ENOENT

New Node & React user here. I'm following the React tutorial but run into a problem on my Windows 10 machine:
C:\Users\Wout>create-react-app my-app
Creating a new React app in C:\Users\Wout\my-app.
Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts...
npm ERR! path C:\Users\Wout\my-app\node_modules\abab
npm ERR! code ENOENT
npm ERR! errno -4058
npm ERR! syscall rename
npm ERR! enoent ENOENT: no such file or directory, rename 'C:\Users\Wout\my-app\node_modules\abab' -> 'C:\Users\Wout\my-app\node_modules\.abab.DELETE'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Wout\AppData\Roaming\npm-cache\_logs\2018-03-14T15_21_11_867Z-debug.log
Aborting installation.
npm install --save --save-exact --loglevel error react react-dom react-scripts has failed.
Deleting generated file... node_modules
Deleting generated file... package.json
Deleting my-app / from C:\Users\Wout
Done.
Things I've tried so far:
Reinstall Node.js (v8.10.0, npm 5.6.0)
Disabling Adobe creative cloud sync & related processes (these were spawning node.exe processes)
Running CMD in admin
Run the command from VS Code Powershell
Closing Visual Studio Code before executing the command
Run the command with npx
Rebooted the system several times
Running the command from the user folder as well as other drives
Running the Typescript version: create-react-app my-app --scripts-version=react-scripts-ts
It's all quite strange to me, since on Mac OS X the command executes without issues. I also can't seem to find other people with the same problem.
For what it's worth, it always stops after this "finalizing abab" package step.
I have an installation of XAMPP running an Apache and MySQL service, don't know if that has anything to do with it. I don't think so since I'm not even running the app yet, plus the server runs on port 3000 anyway.
I eventually solved it by closing as many extra processes as possible. Will try to find out which process was interfering with the command.
Edit: Ding ding ding! It was MalwareBytes! The "realtime protection 30-day trial" had restarted after an update and it was screwing with the filesystem.
I also just installed MalWareBytes, and I get the same error. I tried running create-react-app from the CLI as administrator, and while it was running I read your solution, and so I shut down MalWareBytes as the installation was in progress.
It worked, but I don't know if that is because I ran as administrator, or because I shut down MalWareBytes.
But for anyone having this problem, you could also try running your command prompt/powershell with administrator rights.
try running the command from the project directory...
worked for me.
i ran the command from the parent of the project directory for example:
reactApp/hellowworld
run from helloworle directory instead...
In case you have just install the create-react-app command , try to run the command from a new terminal . (re-open another tab).

Installing Angular CLI with npm install fails

I am new to AngularJS, just started an online course.
I am trying to install angular CLI on my computer at work running Windows 7.
I opened command line as administrator and running npm install -g #angular/cli. Installation starts and after a few minutes I get an error:
I see the notification "operation not permitted", but I am the administrator of the computer and the command line I run as administrator.
What am I doing wrong?
The same installation I did on my laptop at home and it was successful.
I am checking with our IT support about other possible causes and will appreciate any help.
This is not a duplicate of Fail to install npm package “npm ERR! errno -4048” or npm install -g angular-cli fails.
Ignoring the error and running gn -v I get the following:
Is this correct? Was Angular CLI installed?
These issues are because of the company proxy settings.
Check with your admin to get the proxy for http or https.
It will be something like this:
http_proxy = http://http.myproxy.com:8000
https_proxy = http://http.myproxy.com:8000
Replace myproxy with the name of company proxy.
Then go to the command prompt and run the following command to set the proxy. Later you can run any command like npm install -g #angular/cli to run. It will work
npm config set proxy http://http.myproxy.com:8000
npm config set https-proxy http://http.myproxy.com:8000
That fsevents library has peculiarities on Windows. So I suggest you ignore the error message and run ng -v from the command prompt to confirm you got the Angular CLI libraries installed.
You need to run the npm commands on node.js command prompt but not on windows command line.
Workaround: install git bash on windows.
As the error message suggest, you don't have some permissions to execute your command.
Depending on your system, you should run the command as an administrator.
Also, don't mix AngularJS (the first Angular framework) and Angular (also known as Angular 2, 4 and 5 now) . They are radically different in their syntax and uses.
Run below command and try installing angular cli again.
npm cache clean -f
This worked for me manytimes.

Resources