My website (react app) returns a blank page after deploying on Heroku. Although, it runs well on localhost. Hence, it most likely has to do with how Heroku run build and/or start.
The error arose after I had to change the scripts in package.json to :
"scripts": {
"start": "react-app-rewired start",
"build": "react-app-rewired build",
"test": "react-app-rewired test",
"eject": "react-app-rewired eject"
},
I had to change from react-scripts to react-app-rewired as it was a requirement to use some libraries (e.g. most web3-related libraries).
Below are my package.json and server.js below. I read others having issues with server.js but it was working fine in my case before I made the changes mentioned above.
Package.json
{
"name": "app",
"version": "0.1.0",
"engines": {
"node": "16.16.0",
"npm": "8.11.0"
},
"private": true,
"dependencies": {
"#appbaseio/reactivesearch": "^3.34.3",
"#biconomy/web3-auth": "^1.0.0",
"#headlessui/react": "^1.7.5",
"#metamask/onboarding": "^1.0.1",
"#testing-library/jest-dom": "^5.16.4",
"#testing-library/react": "^13.3.0",
"#testing-library/user-event": "^13.5.0",
"apexcharts": "^3.35.3",
"assert": "^2.0.0",
"axios": "^0.27.2",
"bn.js": "^5.2.1",
"bootstrap": "^4.6.0",
"browserify": "^17.0.0",
"caver-js": "^1.8.2",
"chart.js": "^3.8.0",
"elliptic": "^6.5.4",
"ethereum-unit-converter": "^0.0.17",
"ethereumjs-util": "^7.1.5",
"ethers": "^5.7.0",
"express": "^4.18.2",
"js-sha3": "^0.8.0",
"moralis": "^1.11.0",
"primeicons": "^5.0.0",
"primereact": "^8.1.1",
"react": "^18.2.0",
"react-apexcharts": "^1.4.0",
"react-app-rewired": "^2.2.1",
"react-card-flip": "^1.1.5",
"react-device-detect": "^2.2.2",
"react-dom": "^18.2.0",
"react-form-stepper": "^2.0.3",
"react-ga": "^3.3.1",
"react-icons": "^4.6.0",
"react-minimal-pie-chart": "^8.3.0",
"react-moralis": "^1.4.1",
"react-router-dom": "^6.4.3",
"react-scripts": "5.0.1",
"react-slick": "^0.29.0",
"react-step-wizard": "^5.3.11",
"react-toastify": "^9.0.5",
"slick-carousel": "^1.8.1",
"stream": "^0.0.2",
"swr": "^2.0.0",
"web-vitals": "^2.1.4",
"web3": "^1.7.5",
"web3modal": "^1.9.8"
},
"scripts": {
"start": "react-app-rewired start",
"build": "react-app-rewired build",
"test": "react-app-rewired test",
"eject": "react-app-rewired eject"
},
"proxy": "https://buckets-backend.herokuapp.com",
"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"
]
}
}
server.js
// server.js
const express = require('express');
const compression = require('compression');
const path = require('path');
const app = express();
app.use(compression());
app.use(express.static(path.join(__dirname, 'build')));
app.get('*', function(req, res) {
res.sendFile(path.join(__dirname, 'build', 'index.html'));
});
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`App is running on port ${PORT}`);
});
Procfile
web: node server.js
I am stuck, any idea how I could debug this?
Heroku will call start script automatically. You need to change the current "start" script to
"start:dev": "react-app-rewired start",
then create a "start" script which calls the server.js file of your server.
// make sure you pass a correct path to server.js
// if server.js is inside server folder, server/server.js
"start": "node server.js",
The issue was related to one of the new package I used: web3auth. According to their docs, the following resolved the problem:
Replace in package.json:
"browserslist": {
"production": [
"chrome >= 67",
"edge >= 79",
"firefox >= 68",
"opera >= 54",
"safari >= 14"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
Source: https://web3auth.io/docs/troubleshooting/react-big-int-error
Related
I've been trying to deploy a React App to Github Pages, and have followed a few tutorials, however I can't seem to find the gh-pages branch that the site gets built from, only the master branch shows up.
When I deploy the app, only the README.md file shows up, or I get a 404 error. My package.json looks like this:
{
"name": "portfolio",
"homepage": "https://samarqureshii.github.io/",
"version": "2.0.0",
"private": true,
"dependencies": {
"#emotion/react": "^11.9.0",
"#emotion/styled": "^11.8.1",
"#mui/icons-material": "^5.6.2",
"#mui/material": "^5.6.3",
"#testing-library/jest-dom": "^5.14.1",
"#testing-library/react": "^11.2.7",
"#testing-library/user-event": "^13.1.9",
"ajv": "^8.11.0",
"classnames": "^2.2.6",
"moment": "^2.29.4",
"node-forge": ">=1.3.0",
"object-path": "^0.11.8",
"postcss": "^8.4.14",
"postcss-normalize": "^10.0.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-router-dom": "^6.3.0",
"react-scripts": "^5.0.1",
"sass": "^1.54.5",
"typescript": "^4.7.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"predeploy": "npm run build",
"deploy": "gh-pages -d build"
},
"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": {
"gh-pages": "^4.0.0"
}
}
I have been trying to implement electron and react together ,with the below package.json
{
"name": "loader",
"version": "0.1.0",
"private": true,
"dependencies": {
"#testing-library/jest-dom": "^5.16.5",
"#testing-library/react": "^13.3.0",
"#testing-library/user-event": "^13.5.0",
"cross-env": "^7.0.3",
"electron-is-dev": "^2.0.0",
"react": "^18.2.0",
"react-countup": "^6.3.1",
"react-dom": "^18.2.0",
"react-icons": "^4.4.0",
"react-idle-timer": "^5.4.2",
"react-loader-spinner": "^5.3.3",
"react-rnd": "^10.3.7",
"react-router-dom": "^6.4.0",
"react-scripts": "5.0.1",
"react-spring": "^9.5.3",
"styled-components": "^5.3.5",
"web-vitals": "^2.1.4"
},
"main": "public/main.js",
"homepage": "./",
"scripts": {
"react-start": "react-scripts start",
"react-build": "react-scripts build",
"react-test": "react-scripts test --env=jsdom",
"react-eject": "react-scripts eject",
"electron-build": "electron-builder",
"release": "yarn react-build && electron-builder --publish=always",
"build": "yarn react-build && yarn electron-build",
"start": "concurrently \"cross-env BROWSER=none yarn react-start\" \"wait-on http://localhost:3000/ && electron .\""
},
"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"
]
},
"devDependencies": {
"concurrently": "^7.5.0",
"electron": "^21.2.3",
"electron-builder": "^23.6.0",
"wait-on": "^6.0.1"
}
}
It is clear that concurrently is being used to run all the commands together at same time. Now when I do yarn start, all commands are executed along with the react-start, but even after the react is available at http://localhost:3000 the wait-on never executes further and is stucked, eventually the electron never starts.
If tested without wait-on then all commands are executed well along with the electron.
Can someone guide on this?
I had the same issue.
All I needed to do was to change it from wait-on http://localhost:3000 to wait-on http://127.0.0.1:3000.
Hope that helps!
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.
I have an app almost ready to package, I've been using express, react, bootstrap and electron. I can run the app file using npm start, But i cant package it. Build completes and when i run application file electron open but neither react runs on localhost nor express.
My directory structure is as follows
- api
- containes expressjs (package.json)
- client
- containes react and electron (package.json)
*let me know if you need more detailed structure
This is my procfile
react: npm run react-start
electron: npm run electron-start
express: npm start --prefix ../api/
This is my package.json
{
"name": "POSifier",
"version": "0.1.0",
"description": "system",
"private": true,
"homepage": "../",
"dependencies": {
"#date-io/date-fns": "^1.3.13",
"#material-ui/core": "^4.11.0",
"#material-ui/icons": "^4.9.1",
"#material-ui/pickers": "^3.2.10",
"#testing-library/jest-dom": "^4.2.4",
"#testing-library/react": "^9.5.0",
"#testing-library/user-event": "^7.2.1",
"#wojtekmaj/react-datetimerange-picker": "^3.0.0",
"bootstrap": "^4.5.2",
"canvasjs": "^1.8.3",
"custom-electron-titlebar": "^3.2.5",
"date-fns": "^2.16.1",
"jquery": "^3.5.1",
"jsbarcode": "^3.11.3",
"moment": "^2.29.1",
"mysql": "^2.18.1",
"pouchdb": "^7.2.2",
"pouchdb-authentication": "^1.1.3",
"pouchdb-browser": "^7.2.2",
"pouchdb-find": "^7.2.2",
"pouchdb-react-native": "^6.4.1",
"react": "^16.13.1",
"react-bootstrap": "^1.3.0",
"react-bootstrap-date-picker": "^5.1.0",
"react-dom": "^16.13.1",
"react-fade-in": "^1.1.1",
"react-native": "^0.63.2",
"react-pouchdb": "^2.0.1",
"react-router-dom": "^5.2.0",
"react-scripts": "3.4.3",
"web-vitals": "^0.2.4"
},
"build": {
"appId": "com.Posifier.app",
"files": [
"build/**/*",
"node_modules/**/*"
],
"directories": {
"buildResources": "assets"
}
},
"scripts": {
"start": "nf start -p 3000",
"electron-start": "node src/wait-for-react",
"electron-pack": "build --em.main=build/electron.js",
"preelectron-pack": "yarn build",
"react-start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"electron": "electron .",
"pack": "electron-builder --dir",
"dist": "electron-builder",
"new":"react-scripts build && electron-builder --publish=always"
},
"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"
]
},
"devDependencies": {
"electron": "^11.1.1",
"electron-builder": "^22.9.1",
"foreman": "^3.0.1"
},
"main": "public/electron.js"
}
I deployed a ReactJS + ExpressJS app on heroku and it renders the index.html but without the React App in it. This is the package.json:
{
"name": "spotifyproj",
"version": "0.1.0",
"private": true,
"homepage": "https://whispering-caverns-57172.herokuapp.com",
"dependencies": {
"#testing-library/jest-dom": "^4.2.4",
"#testing-library/react": "^9.5.0",
"#testing-library/user-event": "^7.2.1",
"bootstrap": "^4.5.2",
"compression": "^1.7.4",
"cookie-parser": "^1.4.5",
"cors": "^2.8.5",
"express": "^4.17.1",
"morgan": "^1.10.0",
"path": "^0.12.7",
"querystring": "^0.2.0",
"react": "^16.13.1",
"react-bootstrap": "^1.3.0",
"react-dom": "^16.13.1",
"react-router-dom": "^5.2.0",
"react-scripts": "3.4.3",
"react-spotify-player": "^1.0.4",
"spotify-web-api-js": "^1.5.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"heroku-postbuild": "npm run build"
},
"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"
]
}
}
It works fine locally but wont render the app when its deployed...
Solved it in server.js
You gotta tell express to use the build path and not the src or public directory
app.use(express.static(path.join(__dirname, 'build')))
.use(cors())
.use(cookieParser());