sudo npm run start Admin permissions error? - reactjs

I am trying to run react application as sudo on port 443 but it is throwing permissions error as follows. I tried running the react script with root privileges too but get the same error.
Command used is
sudo npm run start
Error
? Admin permissions are required to run a server on a port below 1024. Probably:
/Applications/Google Chrome.app/Contents/Frameworks/Google Chrome Framework.framework/Versions/91.0.4472.114/Helpers/Google Chrome Helper.app/Contents/MacOS/Google Chrome Helper --type=utility --utility-sub-type=network.mojom.NetworkService --field-trial-handle=1718379636,2199499938256335430,15968884667410910440,131072 --enable-features=BlockInsecurePrivateNetworkRequests,CookieSameSiteConsidersRedirectChain,CriticalClientHint,CrossOriginEmbedderPolicyCredentialless,CrossOriginIsolated,CrossOriginOpenerPolicyAccessReporting,CrossOriginOpenerPolicyReporting,DocumentPolicyNegotiation,EnableNewCanvas2DAPI,ExperimentalContentSecurityPolicyFeatures,FeaturePolicyForClientHints,LangClientHintHeader,OriginIsolationHeader,OriginPolicy,SchemefulSameSite,UserAgentClientHint --lang=en-US --service-sandbox-type=network --enable-experimental-web-platform-features --metrics-client-id=22a9279b-1648-45cf-a03c-0ce68df69ad5 --shared-files --seatbelt-client=27 (pid 887)
in /
Would you like to run the app on another port instead? (Y/n)
I checked port 443 and it is available to listen. I also wrote a script to listen on port 443 on localhost and it is able to bind on this port as a sudo user. No luck with the react app though.
I was able to run react app earlier in the same laptop but something changed and I don't know what. The error is anyway about permissions but I ruled out this possibility.
I feel it has something to do with Google Chrome Helper which react-scripts is trying to run without Admin Privilege.
Also, it could be some other package I installed which may have caused the issue.
I am at a loss here and am not sure how to debug it further. Googling the problem didn't help either. Any help to debug or fix the issue is greatly appreciated. Thanks in advance.
Mac OS Big Sur - version 11.4
npm version 7.18.1

I was able to get around this issue, by using this package.json command:
{
"scripts": {
"start-https": "sudo PORT=443 HTTPS=true react-scripts start"
}
}

I met the same issue, and solved by downgrading the node version from 16 to 14, don't know why but works.

The only way I found it to work (especially when you install node and npm using nvm) is to call react-scripts directly:
sudo node ./node_modules/.bin/react-scripts start
This assumes you are in the project / repository directory containing .node_modules. Nevertheless, it is different question whether its correct to npm start with sudo. I was just experimenting to run the dev server on port 80 and it was giving error
Admin permissions are required to run a server on a port below 1024.
And I was unable to fix it with various solutions specified on these links: 1, 2, 3, 4. From these links I mostly tried configuration related solutions as I did not wanted to reinstall node (without nvm).

Related

Deploy error An unexpected error occurred: "ESOCKETTIMEDOUT". App Service Azure

I have a big problem trying to deploy a react app to a azure app service with visual studio azure app service extension, im getting this error
info There appears to be trouble with your network connection. Retrying...
error An unexpected error occurred: "https://registry.yarnpkg.com/date-fns/-/date-fns-2.0.0-alpha.27.tgz: ESOCKETTIMEDOUT".
Im using yarn and i read that increase the network timeout maybe solve this. But how i can do it?
I am using yarn and i read that increase the network timeout maybe
solve this. But how i can do it?
You can try running it in your terminal :
$ yarn install --network-timeout 1000000
And also try to clear the cache by running the below cmd
$ yarn cache clean
$ yarn // to install dependencies, no need for "yarn install"
Please refer the below links for more information:
.yarn is having troubles with the network connection | SO THREAD .
. React deployment keeps failing with ESOCKETTIMEDOUT | MS Q&A
Try to NOT run build on Azure. Do this by answering NO when you publish.
Have you already made the settings to build on Azure (answered yes) .. undo by deleting the following files
.vscode\settings.json
.deployment
Create the file .yarnrc, and write into file:
network-timeout 1000000
Save file & deploy your app with the file

opam init fails - unable to create temp file

I have installed opam 2.1.0 on a Linux Virtualbox VM. When I try opam init, I get the following error:
<><> Fetching repository information ><><><><><><><><><><><><><><><><><><><><><>
[ERROR] Could not update repository "default": OpamDownload.Download_fail(_, "Curl
failed: \"/snap/bin/curl --write-out %{http_code}\\\\n --retry 3
--retry-delay 2 --user-agent opam/2.1.0 -L -o
/tmp/opam-32196-d33843/index.tar.gz.part --
https://opam.ocaml.org/index.tar.gz\" exited with code 23")
[ERROR] Initial download of repository failed.
Running with --disable-sandboxing doesn't help. I know that its a problem creating/writing to /tmp/opam-... directory because if I replace that with my current directory or home directory the command by itself runs fine. It also runs fine with /tmp/opam-... if I use the --create-dirs option in curl but I don't have any way of getting opam init to use that option. Any ideas?
thanks
Update
The reason opam init failed for me was because curl was installed with snap on my system. This exactly what is going on with your VM.
Try to run opam init -verbose and that could reveal more about why you ran into an error.
In my case I needed to install other things with opam and it kept failing every time. So snap uninstall curl and then sudo apt install curl fixed things. (Was only able to figure this out with help from my professor)
Workaround
I ran into the same issue and I found a workaround on the OCaml forum: here. (Credits to UnixJunkie)
You can run:
opam init github git+https://github.com/ocaml/opam-repository.git
This should avoid the certificate issues. This worked for me.
I tried to fix the certificate issues using this answer as well. You could try doing that, but it seems complicated when the workaround is to simply point it to the github repo directly.
This question is similar to this one.

React.js not connecting to (localhost) Ganache on EC2: ERR_CONNECTION_REFUSED 127.0.0.1:8545

Using the following installation on Ubuntu Server 20.04 :
sudo apt-get update
sudo apt-get install nodejs
sudo apt install python2
sudo apt install npm
npm install ganache-cli
npm install node-gyp#3.6.2
npm install truffle#5.1.39
sudo npm install create-react-app#3.3.1 -global
npm install
I am having the error
Failed to load resource: net::ERR_CONNECTION_REFUSED 127.0.0.1:8545/:1
I am running ganache with the command line interface:
I can test the connection via node command prompt
To which I am able to verify a connection to ganache private blockchain
Then I try App.js in React
obtaining the following error:
I have tried the following:
1.) Setting up a proxy under package.json : http://127.0.0.1:8545
2.) Trying http://0.0.0.0:8545
3.) Setting up a middleware proxy account as presented in the following solution:
https://medium.com/bb-tutorials-and-thoughts/react-how-to-proxy-to-backend-server-5588a9e0347
"proxy": "http://127.0.0.1:8545"
4.) addressing cache related issues through rm -r package-lock.json node_modules and npm install updating react.js to latest version
5.) trying different port: 7545
6.) updating react to latest version on ubuntu
I figured it out - thanks to all who reviewed my problem. - hopefully this will help someone in the same situation. To connect to an ec2 instance with React.js / blockchain dapp you need to follow five steps:
1.) set appropriate security rules (you will need to allow access for an instance to reach your server) I set the following rules in a very liberal fashion since this was only a test:
you need to start ganache with explicit chainId specified and a direct reference to your public domain IPv4 DNS domain e.g (
http://ec2-54-186-149-26.us-west-2.compute.amazonaws.com)
the command should look as follows:
3.) the same domain mnemonic needs to be specified in metamask (along with an imported account from your ganache server ) It should look as follows:
4.) React.js also needs to access the domain from EC2 directly (do not use localhost ,even you are running on the server the loopback will not work! - also do not use a shortcut with or (||) condition as that also produced errors for me ). It should look similar to below:
5.) your smart contracts also need this domain specified explicitly - so you will also need to edit your truffle-config.js as follows:
Finally i can read my blockchain via React.js on a test network (ganache) via EC2.
Below is blockchain data presented to screen.
I hope this helps someone out there - this was not found easily.
regards
John D.

Expo, java.net.SocketTimeoutException:failed to connect

am new to React native Expo I need to add some new modules on my project. "expo": "33.0.0", "react": "16.8.3", whenever I try to run my project am getting Error am not able to run the project. I tried all way to run the project like set REACT_NATIVE_PACKAGER_HOSTNAME='192.168.0.102', firewall off, allowed inbound 19000 port etc. but am getting error.
when I enter expo start -c
Your project may not work correctly until you install the correct versions of the packages.
To install the correct versions of these packages, please run: expo install [package-name ...]
Starting Metro Bundler on port 19001.
Your JavaScript transform cache is empty, rebuilding (this may take a minute).
Your native app is running at exp9c305c55e38f4d0e856f59397620314e://192.168.0.101:19000
Logs for your project will appear below. Press Ctrl+C to exit.
then my laptop and mobile is connected with same network and same IP but am getting error and i don't know the port 19000 is different from my wifi
Uncaught Error:java.net.SocketTimeoutException:failed to connect to/192.168.1.20(port 19000)from/192.168.0.102(port 49615) after 10000ms
Please give some solution for it.
It's failing because port 19000 is not open in your firewall. If you use linux OS open this port by running:
sudo ufw allow 19000/tcp
enter image description hereFirst Check are you in tunnel connection?
If you are in tunnel connection then
First : ipconfig
then : set REACT_NATIVE_PACKAGER_HOSTNAME=192.168.1.103 (IPv4 Address)
then:npm start
It worked for me. Hopefully it will help.
I resolved this by changing the network profile on the connected wifi from private to public.
Expo Error Fix

Starting jetty fail in ubuntu 14

I install the solr-jetty package in a Ubuntu 14 container running in a cloud9 workspace.
To install the package I run the following command:
sudo apt-get install solr-jetty
The installation doesn't return any error.
Then I try to start solr with the following command:
sudo service jetty start
But I receive the following error:
* Starting Jetty servlet engine. jetty
* Jetty servlet engine started, reachable on http://host-solr-3694477:8983/. jetty
...fail!
In the log file of jetty I get the following message:
failed setting default capabilities.
set_caps(CAPS) failed for user 'jetty'
Service exit with a return value of 4
How can I resolve this issue?
To resolve the problem I had to change the user that run jetty from jetty to root.
This can be configured by editing the /etc/default/jetty file.
I think it is not the more correct solution because it can add security problems. If anyone have a better solution ...
Docker user here, same problem, but - this worked for me (and this is as unadvised as changing the user to 'root', suggested above):
https://docs.docker.com/engine/reference/run/#/runtime-privilege-and-linux-capabilities
Set the following on your 'docker run' command when creating a container:
--privileged=true
I'm just using docker for development, so not overly concerned yet with the security implications of this.

Resources