500 Internal Server Error: npm#latest - npm

I have a problem with npm I can't get any package. For example running :
npm install -g npm#latest
gives :
npm ERR! code E500 npm ERR!
500 Internal Server Error: npm#latest
If I try to access https://registry.npmjs.org/ I get :
Fastly error: unknown domain.
Please check that this domain has been added to a service.
I looked into my /etc/hosts and nothing wrong there, any ideas ?
---------------- INFOS -----------
NodeJS : v9.2.0
npm : 6.0.1
OS : Ubuntu 16.04.4 LTS

Below step resolve my npm registry issue. I hope same will be work for you.
Try to set npm registry using : npm config set registry https://registry.npmjs.org/
Check result of curl https://registry.npmjs.org/
Clear the cache: npm cache clean --force
Try to run npm install

From corporate network sometimes you won't be able to properly resolve registry.npmjs.org. To workaround the problem do the following.
dig registry.npmjs.org #1.1.1.1
Take any of the ip in the output and add to /etc/hosts
104.16.16.35 registry.npmjs.org
You should be good to go now.

I also faced the same issue.
Below solution worked for me at least:
comment out this part in windows hosts file
# 151.101.0.162 registry.npmjs.org

500 error indicates issue with the server. Yesterday I was facing this issue whenever I tried installing packages with npm. Upon searching a bit, I found status.npmjs.org. It's a page that shows the current status of npm registry. There was an outage due to DNS misconfiguration which was mentioned on the page.I kept checking the status page, and eventually there was a status update :
Update - This has now been resolved for most users and we will continue to monitor until it has cleared for everyone.
Sep 1, 17:13 UTC
After this update, I was able to install packages without any issues.

Related

Error 403 - Forbidden while trying npm install

So just like every day I do different projects and install additional modules, today I want to install another module and such an error, reinstall the server and still the same .... [Error]The error appeared overnight
I found the issue from here: https://github.com/npm/npm/issues/2119#issuecomment-5321857
It's a very common issue in npm. Actually npm is not working good with HTTPS over a proxy. Changing the registry URL from HTTPS to HTTP will fix the problem.
Try this out:
npm config set registry http://registry.npmjs.org

JFrog private registry fails to npm install

I'm having issues with JFrog NPM private repositories.
In our CI we configure the npm private registry and then do npm install like this:
- npm_private_registry https://DOMAIN.jfrog.io/DOMAIN/api/npm/npm-virtual/ $TOKEN
- npm install
This code works perfectly fine when we use the node:12.13.1 Docker image.
Our problem is that as soon as we change the image to a newer one, let's say node:12.16.1 then the npm install command fails.
We then get the following errors:
$ npm install
(wd=/builds/DOMAIN/APP)
npm WARN tar ENOENT: no such file or directory, open '/builds/DOMAIN/APP/node_modules/.staging/react-icons-921e2ffa/go/package.json'
npm WARN tar ENOENT: no such file or directory, open '/builds/DOMAIN/APP/node_modules/.staging/intl-58a6f707/locale-data/jsonp/gsw-FR.js'
...
...
...
npm ERR! Response timeout while trying to fetch https://DOMAIN.jfrog.io/DOMAIN/api/npm/npm-virtual/next (over 30000ms)
We tried various approaches already, but haven't been able to figure anything out just yet.
Does anyone have an idea where to start?
The issue seems quite generic. How is it possible to get timeouts on one version of the node image and no issues on another?
Thank you!
Seems like this link https://github.com/npm/cli/issues/1151 offers some explanation. The timeout got hardcoded down to 30000 ms in npm 16.4.0 via npm-registry-fetch. This has now been reverted to not timeout again https://github.com/npm/npm-registry-fetch/commit/fc5d94c39ca218d78df77249ab3a6bf1d9ed9db1. This fix is in 6.14.5 of npm https://github.com/npm/cli/releases/tag/v6.14.5.
In terms of default npm with node versions this means, releases 12.16.2 and 12.16.3 of node contain this problem via npm 6.14.4.

ERROr: **npm ERR! Unexpected token < in JSON at position 0 while parsing near '<!DOCTYPE HTML PUBLI...'**

Image I am cloning the sitecore Habitat project to my local machine.
After cloning while running npm install, I am getting this error. I tired in all possible ways from the stack overflow answers, but did not succeed with answers still its showing errors, if anyone known about this please let me know.
ERROr: **npm ERR! Unexpected token < in JSON at position 0 while parsing near '<!DOCTYPE HTML PUBLI...'**
Just delete
package-lock.json file
It works for me.
I getting error like:
I found this solution in another question and worked for me after I set the registry like this:
npm set registry https://registry.npmjs.org/
Setting npm Registery worked for me
npm set registry https://registry.npmjs.org/
This error means there is a proxy in the middle which is denying you access to the Internet.
The error comes from the HTML page that is rendered from the proxy.
You need to check with your network administration to either allow the connection through (an exception), or you have to configure the variable HTTP_PROXY in your environment, which is like this:
http://username:password#proxy.server.com:port
Having tested npm install in several repos with the same error I ran npm cache clean --force and tried again. This is not as severe a solution as deleting all traces of node and reinstalling from the ground up.
I use an npm registry hosted at work for internal npm packages so couldn't change the registry source.
yes , its happned due to proxy setting, if this problem occurs, please check your proxy setting, in my case npm was getting blocked, You need to check with your network administration to either allow the connection through (an exception), or you have to configure the variable HTTP_PROXY in your environment
You need to check all required npm config setup like:
https-proxy=https://username:password#accessdomain:port/
proxy=http://username:password#accessdomain:port
registry=https://registry.npmjs.org/
//If required also add
msbuild_path=C:\Program Files\Microsoft Visual Studio\2022\Community\Msbuild\Current\Bin\MSBuild.exe
I was getting the same issue. I had un-installed NodeJs and deleted folders npm and npm-cache from Users\username\Appdata\Roaming folder and installed it.
Then set config registry by using command terminal as.
npm config set registry https://registry.npmjs.org/
To give an actual description of the problem and solution:
This happens when the URL set as your npm registry is incorrect (or as others have mentioned, a proxy has got in the way). Either way, you end up trying to download a package from an endpoint displaying HTML, which npm fails to parse as JSON (as one would expect).
You can view the URL for your npm config with
npm config get registry, and set it with npm config set registry https://my.registry.com/ (or https://registry.npmjs.org/ for the public registry)
I tried everything mentioned here. Nothing worked. Then I moved jsonwebtoken dependency to the bottom of package.json ( Below my registy specific dependencies ).
Then it worked!
Spent 6 hours in fixing this. I feel so small now.

How to fix timeout for packages on `npm install`?

When I run npm install it seems to work fine until part way installing packages. It seems to have no problem with the first half, but then after a while it will fail to be able to reach other packages. I just get the repeating errors, eg:
npm http request GET https://registry.npmjs.org/react-hot-loader
npm info attempt registry request try #3 at 6:43:34 AM
npm http request GET https://registry.npmjs.org/react-tap-event-plugin
npm info attempt registry request try #3 at 6:43:34 AM
npm http request GET https://registry.npmjs.org/react-test-renderer
etc.
It will continue to do this for an hour and and then the install will fail.
The install breaks at a different package each time so I don't think it's a problem with a particular file.
I can access these files fine with my browser and curl.
My work has a firewall but this domain is whitelisted.
Would anyone know what I could do to get this to work or what could be causing it?
If it's about the timing problem you should find a speed solutions for npm install.
So you can try these faster command than npm install :
pnpm install %70 faster
or
npm install --no-audit 15% faster
or
npm install --prefer-offline --no-audit 15% faster
check this article for details : speeding up npm install
You can override the max and min timeout in ~/.npmrc.
// npm config ls -l
// add these 2 lines in ~/.npmrc
fetch-retry-maxtimeout = 6000000
fetch-retry-mintimeout = 1000000
If your internet connection is the problem, try increasing the timeout:
npm config set timeout 6000000
The value is a 32-bit int.
If it's still relevant or maybe for other people of interest: For me it helped, deleting the package.lock file and running npm cache clean --force.
It might not be your case, but I had issues with a package being hosted at github with the repo url being only with git protocol (port 9418 not usually open on firewall).
Once added that to the firewall I could npm install without issues.
You can view the repository url with:
$ npm view zone.js repository.url
git://github.com/angular/angular.git
I saw an answer earlier that can resolve your problem by overriding the max and min timeout in ~/.npmrc file, but some didn't understand how to do it.
First go to the nodejs folder - for me it's located at ( Y:\Program Files\nodejs )
Open the node_modules folder.
Then npm folder.
Select (.npmrc) file + right click and open it with any text editor you want.
Finally add these 2 lines and click Ctrl+S
fetch-retry-maxtimeout = 6000000
fetch-retry-mintimeout = 1000000
.npmrc file after modification
npm cache clean --force
npm install --force
It works fine.
If you are on windows, try running vscode as administrator, it worked for me, I tried npm config delete https-proxy , npm config delete proxy and , tried deleting node_modules, and package.lock.json and ran npm cache clean --force but at last ran vscode as adminitrator before deleting node_modules and package.lock.json, it worked
I solved the timeout issue by executing these commands:
rm package-lock.json
npm i

How to figure out why does the npm hang?

I'm suffering from the infamous npm install (update) hanging problem.
So far I found following recipes:
cleaned the cache: npm cache clean
deleted npm_modules in my project
set the registry to plain http (http://registry.npmjs.org/): npm config set registry http://registry.npmjs.org/
used --loglevel=verbose flag with npm install
increased number of connections as described here:
Increasing the maximum number of tcp/ip connections in linux
Yet it still hangs. The position at which it hangs seems to be random. It can be
npm verb get saving gulp-traceur to /home/me/.npm/registry.npmjs.org/gulp-traceur/.cache.json; or when installing npm verb afterAdd /home/me/.npm/q/0.9.7/package/package.json the last package downloaded is really random.
The versions are:
npm info using npm#2.7.5
npm info using node#v0.12.0
So the question is if there is anything else I can do about it?
I don't know if you have the same problem as I did but I can't make a comment to your question because I have not enough reputation.
Today somebody found solution to my similar problem. You can check it here:
Sometimes you need to use --force command to make sure the cache is cleaned:
npm cache clean --force.
Maybe related to this issue.
I tried all the above. I use homebrew and had to uninstall node / npm.
This worked for me:
brew install nvm
nvm install node
Afterwards npm started working again for me.