Failed to Deploy React App to Heroku - Unable to Deploy - reactjs

I have made a reactjs app. It's just the front-end. So no nodes and databases are added. When I am trying to deploy it to Heroku, I am always facing the same error and couldn't resolve it. I have added the logs and my package.json file.
Package.json
{
"name": "reactapp",
"version": "0.1.0",
"private": true,
"engines": {
"node": "12.17.0",
"npm": "6.14.4"
},
"dependencies": {
"#material-ui/core": "^4.11.0",
"#material-ui/icons": "^4.9.1",
"#testing-library/jest-dom": "^4.2.4",
"#testing-library/react": "^9.5.0",
"#testing-library/user-event": "^7.2.1",
"bootstrap": "^4.5.0",
"font-awesome": "^4.7.0",
"react": "^16.13.1",
"react-bootstrap": "^1.0.1",
"react-dom": "^16.13.1",
"react-helmet": "^6.1.0",
"react-rating-stars-component": "^1.1.0",
"react-router-dom": "^5.2.0",
"react-script-tag": "^1.1.2",
"react-scripts": "3.4.1",
"reactstrap": "^8.5.1",
"shards-react": "^1.0.3",
"styled-components": "^5.1.1",
"typescript": "^3.9.5"
},
"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": {}
}

You're trying to start your app in production with react-scripts start which is actually meant for development. To deploy a Create React App you need to build it and have a server that serves the build folder. That's because you're essentially building a static frontend application instead of a fully fledged backend API, which is what Heroku usually is for.
If you want to deploy with Heroku, you need to use the Create React App buildpack. You can add a buildpack to an existing dyno in the settings section of the UI or in using the heroku CLI:
heroku buildpacks:set mars/create-react-app -a APP_NAME
From next release onwards your app will use the buildpack. For further explanation visit the buildpack repository linked above.

Related

Why am I getting a "module not found" when using console.log in my react application?

I am attempting to use console.log() to be able to verify some values in my react application, but as soon as I type console.log() anywhere within any .js file in the src folder, the page doesn't load anymore and an error is thrown, saying I cannot import the file console-browserify/index.js because it falls outside of the src folder.
I have bootstrapped the project with npx create-react-app and normally I don't face any problems.
Here is the error as well as my package.json file : enter image description here
{
"name": "lovebook",
"version": "0.1.0",
"private": true,
"dependencies": {
"#emotion/styled": "^11.9.3",
"#mui/material": "^5.8.6",
"#mui/x-date-pickers": "^5.0.0-beta.0",
"#testing-library/jest-dom": "^5.16.4",
"#testing-library/react": "^13.3.0",
"#testing-library/user-event": "^13.5.0",
"#web3auth/web3auth": "^1.1.0",
"console": "^0.7.2",
"console-browserify": "^1.2.0",
"date-fns": "^2.28.0",
"grommet": "^2.25.0",
"grommet-icons": "^4.7.0",
"magic-sdk": "^7.0.0",
"moralis": "^1.8.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-moralis": "^1.4.0",
"react-router-dom": "^6.3.0",
"react-scripts": "5.0.1",
"styled-components": "^5.3.5",
"web-vitals": "^2.1.4",
"web3uikit": "^0.1.163"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
make sure you type "cd (your project path name)" when you create a new terminal, so any excess packages don't get installed into the node modules problem. Maybe you should recreate the project and check whether the error keeps showing. At last I'm not sure if it's gonna help much, but try reloading the server you're running your application on

Invalid Host header when I visit my website with my own domain

everyone!
I have one problem with React project.
I developed one React Project and hosted on the AWS Lightsail server.
I set Port of React as 80.
My site is working well with IP address, You can check my website with this url: http://54.80.46.251/
But it is not working with the domain. you can check my website with this url: https://peezee.org/
This is Package.json file of project
{
"name": "my-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"#reduxjs/toolkit": "^1.8.0",
"#testing-library/jest-dom": "^4.2.4",
"#testing-library/react": "^9.5.0",
"#testing-library/user-event": "^7.2.1",
"axios": "^0.26.1",
"bootstrap": "^5.1.3",
"ngrok": "^4.3.1",
"node-sass": "^7.0.1",
"react": "^17.0.2",
"react-bootstrap": "^2.2.0",
"react-dom": "^17.0.2",
"react-redux": "^7.2.6",
"react-router-dom": "^6.2.2",
"react-scripts": "5.0.0",
"redux-devtools-extension": "^2.13.9"
},
"scripts": {
"start": "set PORT=80 && 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": {
"source-map-loader": "^3.0.1",
"webpack": "^5.70.0",
"webpack-cli": "^4.9.2",
"webpack-dev-server": "^4.7.4"
},
"proxy": "http://54.80.46.251:5000/"
}
If you know this problem solution, Please help me.
Thanks.
I solved this issue on my dev environment by adding DANGEROUSLY_DISABLE_HOST_CHECK=true to the .env file.
You might want to check this GitHub issue out.
https://github.com/gitpod-io/gitpod/issues/628
I solved this issue with below link
https://create-react-app.dev/docs/proxying-api-requests-in-development/
Thanks

Bad Gateway in an express and react app deployed on Elastic Beanstalk despite a successful build

I am trying to deploy an express app with react as a front end framework on Elastic Beanstalk. The build succeeds however the website always returns with a Bad Gateway 502. I am trying to build the react app on eb and start the node.js server after react builds successfully, using a deploy script defined in package.json and a Procfile.
Package.json
{
"name": "ecosys",
"version": "0.1.0",
"private": true,
"dependencies": {
"#testing-library/jest-dom": "^5.11.4",
"#testing-library/react": "^11.1.0",
"#testing-library/user-event": "^12.1.10",
"axios": "^0.24.0",
"cross-env": "^7.0.3",
"express": "^4.17.2",
"history": "5",
"i18next": "^21.6.4",
"i18next-browser-languagedetector": "^6.1.2",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-i18next": "^11.15.2",
"react-icons": "^4.3.1",
"react-query": "^3.32.1",
"react-router-dom": "6",
"react-scripts": "^4.0.3",
"react-select": "^5.2.1",
"react-toastify": "^8.1.0",
"react-transition-group": "^4.4.2",
"styled-components": "^5.3.3",
"web-vitals": "^1.0.1"
},
"scripts": {
"start": "node server.js",
"build": "react-scripts build",
"deploy": "npm run build && npm run start",
"dev": "react-scripts start",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
Procfile
web: npm run deploy
I think that the react build succeeds but it never launches the node.js server, It never runs npm run start.

Heroku R14 warning for no apparent reason maybe strict mode problem?

I am getting a R14 warning on my app so I did reduce my app to only the home page to track the issue but what happened is the warning is still there any idea what might cause this ? I am kind of afraid that my package.json is wrong, so basically my app is only home page no functionality nothing could it be that my starting scripts are wrong and the app is starting in dev ? also I have and issue with strict mode how to disable strict mode in production ? I had to comment out the strict mode because the app is getting deployed on strict mode for some reason ?
2022-01-10T19:45:53.658182+00:00 heroku[web.1]: Process running mem=551M(107.7%)
2022-01-10T19:45:53.663719+00:00 heroku[web.1]: Error R14 (Memory quota exceeded)
{
"name": "app",
"version": "0.1.0",
"private": true,
"engines": {
"node": "14.17.4",
"npm": "6.14.14"
},
"dependencies": {
"#emotion/react": "^11.7.1",
"#emotion/styled": "^11.6.0",
"#material-ui/core": "^4.12.3",
"#material-ui/icons": "^4.11.2",
"#material-ui/lab": "^4.0.0-alpha.60",
"#testing-library/jest-dom": "^5.14.1",
"#testing-library/react": "^11.2.7",
"#testing-library/user-event": "^12.8.3",
"#types/html2canvas": "^1.0.0",
"#types/jest": "^27.0.2",
"#types/jspdf": "^2.0.0",
"#types/node": "^16.11.6",
"#types/react": "^17.0.33",
"#types/react-dom": "^17.0.10",
"#types/react-router-dom": "^5.3.2",
"#types/uuid": "^8.3.3",
"html2canvas": "^1.3.3",
"jspdf": "^2.4.0",
"notistack": "^1.0.10",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-ga": "^3.3.0",
"react-router-dom": "^5.3.0",
"react-scripts": "4.0.3",
"typescript": "^4.4.4",
"uuid": "^8.3.2",
"web-vitals": "^1.1.2"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
Your start script runs react-scripts start:
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
That is almost certainly wrong.
Assuming this is a standalone app, React shouldn't actually be running on Heroku. Instead, you should build a production build at compile time and then Heroku just needs to host your files as static files. This uses very little memory.
One option is to use this buildpack, which promises a zero-config way to get apps created via create-react-app up and running on Heroku:
This buildpack deploys a React UI as a static web site. The Nginx web server provides optimum performance and security for the runtime.
Configure your app to use this buildpack:
heroku buildpacks:set mars/create-react-app
Then redeploy.

Deploying react app to heroku giving H10 error code

I've created a react app using create-react-app.It is working well in my local server.But when I tried to deploy it to heroku it is crashing.I don't know why it is crashing.
In heroku logs --tail its showing error code=H10 desc=App crashed.I searched about this issue and nothing helpful for me.
My question is similar to this question : React app runs locally, crashes when on Heroku error code=H10
But I'm unable to understand the solution they given.
My package.json file is as follows:
{
"name": "lets-chat",
"version": "0.1.0",
"private": true,
"dependencies": {
"#fortawesome/fontawesome-svg-core": "^1.2.28",
"#fortawesome/free-brands-svg-icons": "^5.13.0",
"#fortawesome/free-regular-svg-icons": "^5.13.0",
"#fortawesome/free-solid-svg-icons": "^5.13.0",
"#fortawesome/react-fontawesome": "^0.1.9",
"#testing-library/jest-dom": "^4.2.4",
"#testing-library/react": "^9.5.0",
"#testing-library/user-event": "^7.2.1",
"dotenv": "^8.2.0",
"firebase": "^7.14.0",
"moment": "^2.24.0",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-router-dom": "^5.1.2",
"react-scripts": "3.4.1"
},
"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 don't know what's wrong in this file.Should I make any changes in this file to get my problem solved?
heroku logs --tail gave the report as follows:
Check out this link (in case none of the solutions from that other post helped your case): https://dev.to/webdevraj/deploy-a-react-app-on-heroku-the-right-way-5efo
Pay attention to #6 where they mention the buildpack.
When using create-react-app and deploying to
dont delete the favicon.ico and manifest.json
also in package.json above scripts insert "engines": {
"npm": "6.x",
"node": "12.x"
},
//NOTE CHECK YOUR NODE AND NPM VERSIONS BY TYPING npm -v and node -v for accurate versions//
In heroku after heroku create command, go to heroku and change buildback under settings to https://github.com/mars/create-react-app-buildpack
Dont add other scripts or change the start, build scripts!
This should clear all h10 errors when deploying to heroku, if they dont i suggest you create a new directory and copy your files there and start over, this link is a great guide to deploy
https://dev.to/smithmanny/deploy-your-react-app-to-heroku-2b6f
I also had same issue. I could figure out it is something to do with react version.
I changed the version and it worked. Update your version in package.json and see if it works.
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-router-dom": "^5.1.2",
"react-scripts": "3.2.0"

Resources