HumanHickory
HumanHickory

Reputation: 504

How do I deploy an Angular 13 application to Git Hub Pages and not get Readme or 404

tldr; I think I need to add a github token. I have a token from github, but I have no idea how to implement it at the stage that I'm at.

I am trying to deploy an angular 13 app to github pages. Right now, it is just the auto-generated app (I haven't added or changed any code at this point). Here are the steps I have taken

Step 1: Create App and make sure it works

ng new <appName>
cd <appName>
ng serve 

Step 2: Create a Repo on Github

Step 3: Check if it automatically connected to a repo (and remove if it's not the one we want)

git remote 
git remote -v
git remote remove origin

Step 4: Connect to correct Git Repo (replace variables with username and project name)

git remote add origin <https://github.com/USERNAME/PROJECT_NAME.git>

Step 5: Push to Git repo

git branch -m main
git add .
git commit -m "initial commit"
git push -u origin main

Step 6: Hosting

npm install -g gh-pages
ng build --prod --base-href /PROJECT_NAME/  (find project name in angular.json at very bottom
gh-pages -d dist

When I do all of this, it shows that it worked. But then, it just loads a 404 error. After a lot of googling, I think it has something to do with a token. So I went and got the token, but I'm not sure what to do with it.

Workflow Updated

P.S. already saw Git Hub Pages not Deploying. (404) and it was unhelpful.

Upvotes: 1

Views: 368

Answers (1)

HumanHickory
HumanHickory

Reputation: 504

The answer was User Error. The code above works and will deploy an app successfully to gitHub pages.

The problem was I was going to https://humanhickory.github.io/ but the ng build --prod --base-href had actually created a new folder which I had to navigate to (so https://humanhickory.github.io//)

Futhermore, I was able to use the token by running gh-pages -d dist a second time. The first time I did it it said "remote: Invalid username or password. Fatal: authentication failed for '....'". However, when I ran the same command a second time, it prompted me to log in. So there's that.

Upvotes: 0

Related Questions