Search code examples
angulargithub-pagesangular-cli-ghpages

errors when hosting the angular application through GitHub pages


i came across the below error when i try to deploy my angular application to GitHub pages through

angular-cli-ghpages

error message

these were bash commands that i used when pushing the website to the GitHub

ng build --prod --base-href "https://dinith72.github.io/aiesecLoginForm/" - to create the build version

ngh --dir dist/AiesecLogin -m "adding request for python serve"

i tried the options mentioned in the above git issue posted but could not find a solution to my issue . Thank you very much in advance .


Solution

  • I have use travis-ci for this is better and in every commit will automatically build and deploy github pages and it 's not that much complicated simply just add travis.yml and update baseurl in angular.json for build

    like this:

    "baseHref": "https://username.github.io/repo-name/"

    as example in my case :

    "baseHref": "https://malbarmawi.github.io/angular-lessons/"

    travis.yml

    language: node_js
    node_js:
      - "9"
    dist: trusty
    sudo: false
    
    branches:
      only:
        - master
    
    cache:
      directories:
        - node_modules
    
    install:
      - npm i @angular/cli@6.2.4 -g
      - npm i
    
    script:
      - ng build --prod
    deploy:
      provider: pages
      skip_cleanup: true
      github_token: $GITHUB_TOKEN
      local_dir: dist/
      on:
        branch: master
    

    finaly get github token , you can check my project

    this the article that help me with this Deploying your Angular app to GitHub Pages using Travis-CI