angularangular-cli

Cannot read property 'call' of undefined - Angular 2 Build error [Potential Solution]


My test server and test code will run perfectly on localhost but when using ng build and hosting built files I get errors and nothing is displayed.

Our test servers for angular 2 CLI working fine but building and testing the project on a live server will render an error like: When running a build like:

ng build --prod --base-href /new/

And uploading the build to a live server will render this issue in my console:

Cannot read property 'call' of undefined

or something similar and seemingly meaningless.


Solution

  • Update To fix this problem when you use --build-optimizer and it still fails, please reinstall node_modules which should pickup @angular-devkit/build-optimizer@0.0.27, to check use this command npm ls @angular-devkit/build-optimizer To reinstall all use this:

    npm uninstall -g angular-cli
    npm cache clean
    npm install -g angular-cli@latest
    

    The solution I found was adding this to my build command:

    --build-optimizer

    If I just ran the following command I would get the 'undefined property call' error and similar seemingly meaningless errors

    ng build --prod --base-href /new/

    with your build command, for example a working command for me was this:

    ng build --prod --base-href /new/ --build-optimizer

    It seems from an angular-cli dev that this error is occurring when the code is deployed due to the order of scripts being loaded in

    Official angular-CLI support/bug thread for this issue, if adding -build-optimizer doesn't fix your issue please refer to there and repo your current non-working build for assistance. https://github.com/angular/angular-cli/issues/6196