How to fix a 404 on react app deployed on github pages? - reactjs

I have tried to deploy my react app on github pages, but am getting a 404 error. However the site is able to access my app as the 404 page is my custom one. I followed the deployment steps from https://github.com/gitname/react-gh-pages.The github page is https://ritsar.github.io/LapStore/ and the respective remote repository is at https://github.com/RitSar/LapStore. I get no errors on the terminal when i run npm run deploy.I am trying to make ritsar.github.io/LapStore my root, i.e to access index.html. On navigating within the site from the navbar, home page is directed to ritsar.github.io/,where images are not accessible and cart is directed to /cart instead of /LapStore/cart.
package.json
{
"homepage": "http://RitSar.github.io/LapStore",
"name": "e-commerce",
"version": "0.1.0",
"private": true,
"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",
"jquery": "^3.5.1",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-owl-carousel": "^2.3.1",
"react-router-dom": "^5.2.0",
"react-scripts": "^3.4.3",
"serialize-javascript": "^4.0.0",
"styled-components": "^5.1.1"
},
"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": "^3.1.0"
}
}
I have tried changing "homepage" to "http://RitSar.github.io", ".", "http://RitSar.github.io/LapStore/index.html", made minor changes to index.html and redeployed, changed branch folder on github settings to /docs from /(root) as per relative suggestions from other threads.
Same app hosted on heroku is at https://lapstore-ritsar.herokuapp.com/. (Page loading slowly despite of images having size less than 50kb is an issue for another time, I would like to know how to correctly deploy the same on github pages).

Your main page with router <Route exact path="/" component={ProductList}></Route>. With exact path, it will not work on gh-page and you need to add 1 more route /LapStore.
Try to remove exact the route and add new route:
<Route path="/" component={ProductList}></Route>
<Route path="/LapStore" component={ProductList}></Route>

Related

404 error after adding custom domain to deployed reactjs app hosted by github pages

I've created a reactjs app and I deployed it to github pages with the command npm run deploy this all works great and I can see my app running when i open it from the
settings>pages in my repo. However, I am trying to add a custom domain and this is causing me trouble. I configured the IPs and everything for the DNS according to gh-pages documentation and the DNS checks all pass when i add the domain name. But when i go to the domain in my browser I get all 404 errors like this:
Im thinking it could be something wrong with my package.json, I was thinking I need to change the "homepage" value to my new domain instead of the http://<Github-username>.gihub.io/<repoName>/ I set it to when i deployed the app? Ive tried this but it doesnt work to load the page at that url.
So Im wondering if anyone has run into this issue after deploying to gh-pages and then adding a custom domain?
this is my package.json:
{
"homepage": "http://CRJones7.github.io/learned/",
"name": "learned",
"version": "0.1.0",
"private": true,
"dependencies": {
"#primer/octicons-react": "^17.9.0",
"#testing-library/jest-dom": "^5.16.5",
"#testing-library/react": "^13.4.0",
"#testing-library/user-event": "^13.5.0",
"bootstrap": "^5.2.3",
"jquery": "^3.6.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.4.4",
"react-scripts": "5.0.1",
"reactstrap": "^9.1.5",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"predeploy": "npm run build",
"deploy": "gh-pages -d build",
"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"
]
},
"devDependencies": {
"gh-pages": "^4.0.0"
}
}
I figured out the solution, I just needed to re-deploy my page with
npm run deploy

GitHub Pages Page Not Found for React App

I am trying to publish my single page website to github pages, but I've run into an issue. When I go to the link for my website, it gives me a 404 error with this message: "File not found. The site configured at this address does not contain the requested file. If this is your site, make sure that the filename case matches the URL. For root URLs (like http://example.com/) you must provide an index.html file."
I've looked at the documentation, watched videos, and looked up other people who are having this issue, but nothing will solve it.
I have a main and a gh-pages branch. Right now I have it set to build from the gh-pages branch. If I change it to main I get the same issue.
Here is my package.json file:
"homepage": "http://bpyle02.github.io/portfolio",
"name": "portfolio",
"version": "0.1.0",
"private": true,
"dependencies": {
"#craco/craco": "^6.4.2",
"#testing-library/jest-dom": "^5.11.4",
"#testing-library/react": "^11.1.0",
"#testing-library/user-event": "^12.1.10",
"aos": "^3.0.0-beta.6",
"autoprefixer": "9",
"gh-pages": "^3.2.3",
"postcss": "7",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-icon": "^1.0.0",
"react-icons": "^4.3.1",
"react-router": "^6.0.2",
"react-router-dom": "^6.0.2",
"react-scripts": "4.0.3",
"react-scroll-into-view": "^1.10.1",
"scroll-into-view": "^1.16.0",
"tailwindcss": "npm:#tailwindcss/postcss7-compat",
"web-vitals": "^1.0.1"
},
"scripts": {
"predeploy": "npm run build",
"deploy": "gh-pages -b main -d build",
"start": "craco start",
"build": "craco build",
"test": "craco 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"
]
}
}
Here is the link to the repo: https://github.com/bpyle02/portfolio
You need to upload only the contents of your build folder to the gh-pages branch. I think it will benefit you to read about how GitHub Pages works.
The create-react-app documentation explains how to address your scenario:
https://create-react-app.dev/docs/deployment/#github-pages
Here's the most important information (without setting this before building your app, it won't work):
Open your package.json and add a homepage field for your project:
"homepage": "https://myusername.github.io/my-app",
Create React App uses the homepage field to determine the root URL in the built HTML file.
This might also be relevant to your app:
https://create-react-app.dev/docs/deployment/#serving-the-same-build-from-different-paths

My react app appears blank after successfully deploying to github-pages

I'm trying to deploy a react app without any routing functionality. Just a single page app to github pages and everything worked successfully. I did'nt get any error while deploying but after deployment, the app is blank and when i check my console i see the following error
GET https://vicktor61.github.io/VickTor61/indecision-sniffle.git/static/css/main.aea680b0.chunk.css net::ERR_ABORTED 404
vicktor61.github.io/:1 GET https://vicktor61.github.io/VickTor61/indecision-sniffle.git/static/js/2.ed9a5867.chunk.js net::ERR_ABORTED 404
vicktor61.github.io/:1 GET https://vicktor61.github.io/VickTor61/indecision-sniffle.git/static/js/main.0913b291.chunk.js net::ERR_ABORTED 404
/VickTor61/indecision-sniffle.git/manifest.json:1 GET https://vicktor61.github.io/VickTor61/indecision-sniffle.git/manifest.json 404
manifest.json:1 Manifest: Line: 1, column: 1, Syntax error.
I understand that the issue probably is because the gh-pages server could not get my files. But i still don't know why. please i will really appreciate a well detailed response.
This is my app link
https://vicktor61.github.io/indecision-sniffle/
and this is my package.json file
{
"homepage": "https://github.com/VickTor61/indecision-sniffle.git",
"name": "indecision-app",
"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.21.1",
"gh-pages": "^3.2.3",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-modal": "^3.14.3",
"react-scripts": "4.0.3",
"uniqid": "^5.3.0",
"web-vitals": "^1.0.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"predeploy": "yarn run build",
"deploy": "gh-pages -d build"
},
"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"
]
}
}
And this is my github page where the whole app is hosted
https://github.com/VickTor61/indecision-sniffle/
As per the official docs, setting the homepage setting as follows in your package.json should fix the issue:
"homepage": ".",
In the docs it is stated:
This will make sure that all the asset paths are relative to
index.html. You will then be able to move your app from
http://mywebsite.com to http://mywebsite.com/relativepath or even
http://mywebsite.com/relative/path without having to rebuild it.
Guessing by the errors on the github page, the page is trying to load files which can't be found. I would say your homepage is wrong. It shouldn't be
"homepage": "https://github.com/VickTor61/indecision-sniffle.git",
it should be
"homepage": "https://vicktor61.github.io/indecision-sniffle",
as the page tries to load for example this file
https://vicktor61.github.io/VickTor61/indecision-sniffle.git/static/css/main.aea680b0.chunk.css
while it should be this file
https://vicktor61.github.io/indecision-sniffle/static/css/main.aea680b0.chunk.css

Blank page when deploying react-table on github pages

I am making simple react.js app using react-table.
I tried to run it locally using npm start and it is working fine.
But when I tried to deploy it on github pages, it just shows a blank page. I have followed all the steps for deploying react app on gh pages.
Here is the gh repository : https://github.com/7phalange7/react-table
the main branch has the project code, and gh-pages branch is deployed on github pages.
Should there be a problem deploying react-table on github pages ?
package.json for reference
{
"name": "react-table-example",
"version": "0.1.0",
"private": true,
"dependencies": {
"#testing-library/jest-dom": "^5.14.1",
"#testing-library/react": "^11.2.7",
"#testing-library/user-event": "^12.8.3",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "^4.0.3",
"react-table": "^7.7.0",
"web-vitals": "^1.1.2",
"homepage": "https://7phalange7.github.io/react-table/"
},
"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",
"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": {
"gh-pages": "^3.2.3"
}
}
Edit :
still not sure what is the issue here, but I copied all the code to a new react project and then deployed on github pages and it is working fine now. I guess since this was the first time deploying react project, somehow I messed up something.
try changing the private to 'false' in your package.json

React app not deploying correctly in Github pages

I followed a tutorial to deploy a React app to github pages. When I deploy, I get no error messages, but when I check the URL, I just see a blank page (see https://bd21.github.io/tallyup-frontend-demo/).
It runs locally fine using "npm start". Whenever I deploy I just run "npm run deploy".
My repository is here: https://github.com/bd21/tallyup-frontend-demo
Here is my package.json:
{
"name": "tallyup-frontend-demo",
"version": "0.1.0",
"private": true,
"dependencies": {
"#fortawesome/fontawesome-svg-core": "^1.2.22",
"#fortawesome/free-solid-svg-icons": "^5.10.2",
"#fortawesome/react-fontawesome": "^0.1.4",
"#types/jest": "24.0.18",
"#types/lodash": "^4.14.138",
"#types/node": "12.7.4",
"#types/react": "16.9.2",
"#types/react-dom": "16.9.0",
"#types/react-router-dom": "^4.3.5",
"bootstrap": "^4.3.1",
"lodash": "^4.17.15",
"moment": "^2.24.0",
"node-fetch": "^2.6.0",
"react": "^16.9.0",
"react-bootstrap": "^1.0.0-beta.12",
"react-dom": "^16.9.0",
"react-router-dom": "^5.0.1",
"react-scripts": "3.1.1",
"typescript": "3.6.2"
},
"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"
]
},
"homepage": "http://bd21.github.io/tallyup-frontend-demo",
"devDependencies": {
"gh-pages": "^2.1.1"
}
}
When I look at the network calls in the Chrome inspector, I don't see any 4xx or 5xx calls. You can verify that here.
https://bd21.github.io/tallyup-frontend-demo/
Why isn't my app deploying/displaying correctly?
your site is working properly in Github pages,
maybe the problem is with your react router code as it was routing something
When you use "npm run deploy", don't you receive any errors?
Cuz if it runs without any errors, «build» directory and «gh-pages» branch created then you can easily change branch of your repository (for github pages in settings) on «gh-pages» branch and after minutes, you can see your own github pages.
If you did all above, check index.html in «build» directory.
It should show an html of your React project correctly.
Another thing i had problem with, you should add origin remote for your repository (not other name just origin) :
Git remote add origin
I hope i'll help you.

Resources