Jim Lynch Codes
  • Blog
  • About Jim

Writings about one coder's stories & experiences.

SOLVED: Problems With Resource Loading Failures When Deploying Angular 2 WebApps Live

9/5/2016

0 Comments

 
I was getting really frustrated recently when trying to deploy my Angular 2 applications live to gh-pages branch to host the sites through Github. I had started Angular 2 projects from three different starter projects (Angular CLI, FountainJS, and Angular Webpack Starter), but all three of them were giving me errors when I deployed the site live! Here's the story of what was happening and how I fixed the issues. 

I was getting this error when deploying an application scaffolded from Angular CLI:
Picture
Then I moved over and tried it on a starter project from the AngularClass's "angular2-webpack-starter" project, but it was giving me these very similarly terrifying errors:
Picture

Fixing These Deployment Errors in General

After fixing the errors in all three projects I can now say that the problems all stemmed from the base url for my projects being "/". This slash means it's an absolute url, and especially when deploying to gh-pages, you should use relative urls instead of absolute. This can normally be solved by changing the slash to a dot! The dot ( . ) represents a relative url, and changing this is the correct spot fixed my projects! Now, in the rest of this post I'll go into specifically where to make this slash-to-dot change in each of the three projects.

Fixing Angular 2 CLI Deployment Errors

For the project that was scaffolded from the Angular CLI using ng new I was able to fix the errors by changing this one single line of code from '/' to './'
Picture

This piece of code was line 9 of app/src/index.html (although that may change over time). After I built the project again and deployed, it worked! 
Picture
I was still getting a strange error in the console about "ember live reload" not being found, but at least my app was running!

Fixing FountainJS Deployment Errors

I had also scaffolded out a project from the yeoman "generator-fountain-webapp". This is a really nice one, and I especially like it because it gives you the option to set up ngRx (Angular 2 Redux) for your project. I was getting similar errors when deploying this project to gh-pages as well, but I was able to fix them by changing the slash to a dot! For this project, the change happeded at line 4 of app/index.html:
Picture
Changing it from "/" to "./" worked, and my deployed site ran cleanly with no errors. Sweet!
Picture

Fixing Webpack Starter Deployment Errors

I opened up this issue and asked this question on stack overflow. Eventually I was able to find the baseUrl for this project. Since this one was scaffolded from the Angular 2 Webpack Starter the line to change was in a slightly different location. For this project I found it on line 22 of config/webpack.common.js, and I just needed to change it from '/' to '.'
Picture
Then I built the project, added the files to git, and pushed to gh-pages. It works!
Picture
0 Comments

Your comment will be posted after it is approved.


Leave a Reply.

    ​Author

    Picture
    The posts on this site are written and maintained by Jim Lynch. About Jim...
    Picture
    Follow @JimLynchCodes
    Follow @JimLynchCodes

    Categories

    All
    Actionscript 3
    Angular
    AngularJS
    Automated Testing
    AWS Lambda
    Behavior Driven Development
    Blockchain
    Blogging
    Business Building
    C#
    C / C++
    ClojureScript / Clojure
    Coding
    Community Service
    CS Philosophy
    Css / Scss
    Dev Ops
    Firebase
    Fitness
    Flash
    Front End
    Functional Programming
    Git
    Go Lang
    Haskell
    Illustrations
    Investing
    Java
    Javascript
    Lean
    Life
    Linux
    Logic Pro
    Music
    Node.js
    Planning
    Productivity
    Professionalism
    Python
    React
    Redux / Ngrx
    Refactoring
    Reusable Components
    Rust
    Security
    Serverless
    Shell Scripting
    Swift
    Test Driven Development
    Things
    TypeScript
    Useful Sites
    Useful Tools
    Video
    Website Development
    WebStorm
    Writing

    Archives

    March 2023
    August 2021
    February 2021
    January 2021
    October 2020
    September 2020
    May 2020
    April 2020
    February 2020
    January 2020
    December 2019
    October 2019
    September 2019
    August 2019
    July 2019
    June 2019
    May 2019
    April 2019
    March 2019
    February 2019
    January 2019
    December 2018
    November 2018
    October 2018
    September 2018
    August 2018
    June 2018
    May 2018
    April 2018
    March 2018
    February 2018
    January 2018
    December 2017
    November 2017
    October 2017
    September 2017
    August 2017
    July 2017
    May 2017
    April 2017
    March 2017
    February 2017
    January 2017
    December 2016
    November 2016
    October 2016
    September 2016
    August 2016
    July 2016
    June 2016
    May 2016
    April 2016
    March 2016
    February 2016
    January 2016
    December 2015
    November 2015
    October 2015

    RSS Feed

  • Blog
  • About Jim
JimLynchCodes © 2023