npm start reports "Something is already running on port XXX" no matter what XXX is - node.js

I am trying to npm start my web app's frontend, and npm start gives me following:
Something is already running on port 3000.
I tried lsof -i :3000 and nothing's running on 3000. I tried modifying package.json to change to another port to start my app, but it still says Something is already running on port XXX no matter what that port is, 3000, 30006, or anything. If I point my browser to localhost:XXX it will just say ERR_CONNECTION_REFUSED because nothing's running there.
I'm pretty sure it's not the code's problem because the app can be started on another machine. Anyway, really desperate for suggestions here. I pasted my package.json as follows:
{
"name": "client",
"version": "0.1.0",
"private": true,
"dependencies": {
"axios": "^0.18.0",
"node-sass": "^4.10.0",
"react": "^16.5.0",
"react-dom": "^16.5.0",
"react-scripts": "1.1.5"
},
"scripts": {
"start": "PORT=30006 react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
},
"proxy": "http://localhost:3001",
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
]
}

Thanks for all the comments, actually this answer helps https://stackoverflow.com/a/49520791/7203672.
I literally tried all methods to kill the process or find the process or reinstall the dependecies but it just never occurred to me that this is a problem with my /etc/hosts. And the problem is I have 126.0.0.1 localhost instead of 127.0.0.1, I probably made a typo some days back, I have no idea.
Lessons learned, should've tried every answer under that post before posting the question.

Related

Why does Firebase disappear from my project?

I've noticed something quite strange. I'm working on this node app using Firebase v8.9.1, and the following two things have happened.
The Firebase package has disappeared from node_modules along with package.json, almost as if my application had been rolled back. The rest of my app is as I last left it.
This is the second time this has happened to me, the first time I thought it was some sort of bug and didn't mind, but today it happened once again, and I'm afraid it might keep happening.
Why does the package disappear? I didn't even close the editor (VSCode).
I'm also using React, in case that's relevant.
Thank you in advance.
This is my package.json after reinstalling firebase:
{
"name": "fastbuy1",
"version": "0.1.0",
"private": true,
"dependencies": {
"#testing-library/jest-dom": "^5.16.5",
"#testing-library/react": "^12.1.5",
"#testing-library/user-event": "^13.5.0",
"bootstrap": "^5.2.2",
"firebase": "8.9.1",
"react": "17.0.2",
"react-bootstrap": "^2.5.0",
"react-dom": "17.0.2",
"react-router-dom": "^5.3.4",
"react-scripts": "^5.0.1",
"uuid": "9.0.0",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"buildDeploy": "yarn build && firebase deploy --only hosting"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
Edit 1: I also realized that in my github repo the package.json does show that Firebase is installed.
Edit 2: Some more information. The last thing I did was deploy the application, and it worked all right. I left the computer for about two hours and when I came back to re deploy the application, I started to receive an auth error: "Your API key is invalid, please check you have copied it correctly." I began to search for the cause, and that's when I realized that Firebase was no longer in my json nor in the modules directory. This error persists, but I'm trying to fix it by myself, and will post another question if I can't find the answer. I hope this gives a bit more clarity to the issue.

'npm start' with create-react-app not launching server on macOS [duplicate]

This question already has answers here:
NPM run * doesn't do anything
(2 answers)
Closed 3 years ago.
After creating an app using create-react-app, I tried using 'npm start' to run the app. Although it doesn't throw an error, it also doesn't launch the server.
For a little context, this command was working a few weeks ago just fine. It would spit out a little bit of text into the console and then lauch a browser at localhost:3000. Since then, I ran into a bug between node and React Native and downgraded to node v10 in order to avoid the bug (although Im currently using node v13). Since then, I have reinstalled node (via homebrew) and reinstalled creact-react-app.
Below are my current specifications
macOS v10.14.5
node v13.5.0
npm v6.13.4
create-react-app v3.3.0
Below is my package.json file
{
"name": "testing",
"version": "0.1.0",
"private": true,
"dependencies": {
"#testing-library/jest-dom": "^4.2.4",
"#testing-library/react": "^9.4.0",
"#testing-library/user-event": "^7.2.1",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-scripts": "3.3.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
I have tried using npm-install-missing to check for missing dependancies. I have also tried removing node modules using 'rm -rf node_modules' and then running 'npm install'.
I am unsure where to go from here. I thought that since 'npm start' calls 'react-scripts start', maybe there was an issue within react-scripts. However, react-scripts should have been reinstalled with create-react-app so im not sure. I am happy to provide more information if there is anything else that I am missing. Thanks!
Edit: When I deleted a previous version of node, I went though and deleted files manulally so that I could reinstall node using homebrew. I thought that I deleted all the proper files, however, if I didn't, could that play a role in this?
Go to your
~\.npmrc
file and see if it contains
ignore-scripts=true
I dont know how or why this was set but it offered many hours of headaches.

how to resolve "EADDRINUSE" error and "Proxy error"?

I have two problems when running my NPM. The first problem is whenever I save my files. I get this error message.
Also when I make a request to the server from my frontend. I get the proxy error message
This is my scripts in my package.json for my backend
"scripts": {
"client": "npm start --prefix client",
"server": "node app.js --ignore client",
"start": "npm start --prefix client",
"dev": "concurrently \"npm run server\" \"npm run client\"",
"test": "echo \"Error: no test specified\" && exit 1"
},
And also my package.json for my client as you can see below
{
"name": "client",
"version": "0.1.0",
"private": true,
"proxy": "http://localhost:5000",
"dependencies": {
"#fortawesome/fontawesome-svg-core": "^1.2.8",
"#fortawesome/free-brands-svg-icons": "^5.6.3",
"#fortawesome/free-solid-svg-icons": "^5.5.0",
"#fortawesome/react-fontawesome": "^0.1.3",
"axios": "^0.19.0",
"react": "^16.10.2",
"react-dom": "^16.10.2",
"react-router-dom": "^5.1.2",
"react-scripts": "3.2.0",
"react-spring": "^8.0.27"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"node-sass": "^4.12.0"
}
}
Assuming you're on windows:
Run netstat -aon to view the processes running on each port
Find the process running on 0.0.0.0:5000 or 127.0.0.1:5000 and note its PID
Run taskkill /F /PID <pid_number> to kill that process
You should now be able to run your npm service on that port
If you're on Linux or Mac you should be able to follow the same process, just google what the commands are called on those OSs
EADDRINUSE tells you, port 5000 is already open by another process or the same process. So either something else is running on the port, or in your case it is more likely your app doesn't close the port properly when restarting.
You can manually force close the process and restart it, but that can be quite a pain, instead of restarting when you save. Since you probably want the latter.
So I'd suggest looking at your code and check for things that could prevent your app from shutting down, or delay your shut down. So Pay attention to things such as promises that have not resolved yet, and timeouts that are still running.
As for your proxy issue you get a ECONNRESET, which basically says your connection has been shut down by the peer (so the proxy in your case), most likely because port 5000 gets shutdown and restarted. I reckon that one will be solved once you resolve your first issue.
Hope this helps with resolving your issue.

How do I get my nodejs app deployment to load next build resources (404 console error strips my website of all react components)

Straight up, the same code deployed two different ways:
npm run dev on my localhost
https://02e7822e.ngrok.io
npm start (I assume) on Google App Engine
https://testing-234701.appspot.com/
I have to stress that this is the same code being deployed (obviously very much tailored in package.json to deploy to App Engine) but only one of them looks correct.
I'm sure we're all thinking it's a problem with package.json, so I'll include it below, but if anyone has ever encountered a similar problem where a nodejs app looks fine on localhost but then looks like shit on deploy, PLEASE LET ME KNOW!
Chrome Console error: Failed to load resource: https://testing-234701.appspot.com/%7BsummarAIze%7D/_next/static/6MuW3BriROYrhZZCL~v03/pages/index.jsthe server responded with a status of 404 ()
^note, the resource that wasn't loaded deals with _next, so it must be related to next.js
package.json
{
"name": "hps_prework",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "node app.js",
"build": "next build",
"start": "NODE_ENV=production && node app.js",
"gcp-build": "npm run build",
"deploy": "npm run build && gcloud app deploy"
},
"engines": {
"node": ">10.0"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"#material-ui/core": "^3.9.2",
"#material-ui/icons": "^3.0.2",
"babel-loader": "^8.0.5",
"jquery": "^3.3.1",
"js-cookie": "^2.2.0",
"koa": "^2.7.0",
"koa-session": "^5.10.1",
"next": "^8.0.3",
"python-shell": "^1.0.7",
"react": "^16.8.4",
"react-dom": "^16.8.4",
"react-scripts": "^2.1.8",
"webpack": "^4.28.3"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
]
}
I should also note that I took some inspiration for my package.json scripts from this prev SO question: Deployed a Next.js application to App Engine Standard [Nodejs] and got a 500 error
I am deploying to App Engine with gcloud app deploy and the logged output from that doesn't show any problems. It's just when the webpage is loaded, everything's just broken.
Edit: I also don't know if this is helpful at all, but I deployed the same app to AWS Elastic Beanstalk and the process was so much easier. The website loaded the same way as it did on my localhost, and AWS EB even lets the user change the npm command used to run the website, which Google App Engine doesn't seem to support.

React-timestamp issue. Can't resolve 'react' in node modules

I'm creating an App with React and everything has been fine for weeks until I installed react-timestamp with npm in order to convert unix time (https://www.npmjs.com/package/react-timestamp).
But now it won't compile and says:
/Users/nembokid/node_modules/react-timestamp/lib/timestamp.js
Module not found: Can't resolve 'react' in '/Users/nembokid/node_modules/react-timestamp/lib'
I've tried to remove package-lock.json as well as yarn.lock, then did npm install again followed by npm run start, but still same issue. Also tried to add it to my package.json file, but without success.
In '/Users/nembokid/node_modules/react-timestamp/lib' there's only one file: timestamp.js. Should it also contain a file called react.js?
How can I get around this? Should I try to delete react-timestamp from my node_modules folder? Don't really understand the issue here. Would be grateful for all help!
Edit: package.json:
{
"name": "client",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^16.6.3",
"react-dom": "^16.6.3",
"react-router-dom": "4.3.1",
"react-scripts": "2.1.1",
"web3": "^1.0.0-beta.37"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
]
}
I deleted the folder /Users/nembokid/node_modules/react-timestamp and then from the terminal, inside the project client folder: npm run start without npm install or anything. Works perfectly fine again.

Resources