Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Alex Brown 129 posts 620 karma points
    Mar 27, 2018 @ 14:40
    Alex Brown
    0

    Client Dependency - Argument is not a function

    Hi All

    Currently running Umbraco 7.9.2 and I've got an error appearing when I set debug to false. I've seen a couple of posts about this but I can't see the problem with what I've done.

    This error is occurring in a custom section which is split into multiple html and js files.

    My code is below. I'll be pasting everything in, sorry there's so much of it.

    The error displays the following:

    Error: Argument 'SizeGuidesManagement' is not a function, got undefined
    

    Package.manifest:

    {
      javascript: [
        "~/App_Plugins/Catalogue/backoffice/Dialogs/product.add.controller.js",
        "~/App_Plugins/Catalogue/backoffice/catalogueTree/edit.controller.js",
        "~/App_Plugins/Catalogue/backoffice/cataloguedashboard.controller.js",
        "~/App_Plugins/Catalogue/product.resource.js",
        "~/App_Plugins/Catalogue/product.service.js",
        "~/App_Plugins/Catalogue/user.resource.js",
        "~/App_Plugins/Catalogue/backoffice/attributesManagement.controller.js",
        "~/App_Plugins/Catalogue/attributes.resource.js",
        "~/App_Plugins/Catalogue/backoffice/Size Guides/Js/sizeGuidesManagement.controller.js",
        "~/App_Plugins/Catalogue/backoffice/Size Guides/Js/sizeGuides.resource.js",
        "~/App_Plugins/Catalogue/backoffice/Size Guides/Js/sizeGuidesDialog.controller.js",
        "~/App_Plugins/Catalogue/Js/interceptors.js",
        "~/App_Plugins/Catalogue/Js/productsNavigationSearch.controller.js",
      ],
    
      "css": [
        "~/App_Plugins/Catalogue/Css/catalogue.css"
      ]
    }
    

    The view which calls this:

    <form name="sizeGuidesManagementForm"
          ng-controller="SizeGuidesManagement as vm"
          ng-show="loaded"
          val-form-manager>
    </form>
    

    The controller which throws the error:

    angular.module("umbraco")
        .controller("SizeGuidesManagement", function ($scope, sizeGuidesResource, dialogService, notificationsHandler) {
            var vm = this;
        });
    

    Also, I use Dashboard.config which says to render this view. Can Dashboard.config have spaces in its location? E.g. below:

      <section alias="catalogue">
        <areas>
          <area>catalogue</area>
        </areas>
        <tab caption="Size Guides">
          <control showOnce="true" addPanel="false" panelCaption="">
            /App_Plugins/Catalogue/backoffice/Size Guides/Views/index.html
          </control>
        </tab>
      </section>
    

    Any help would be appreciated!

  • Kevin Jump 2343 posts 14890 karma points MVP 8x c-trib
    Mar 27, 2018 @ 15:34
    Kevin Jump
    1

    Hi Alex,

    Yes it can be a real pain to debug these - issues :(

    When you set debug to false the client dependency framework is pushing all of your java-script files together into one, which can have unintended consequences, as you get random interference between the scripts.

    The best advice I have is to wrap all of your code in a function set the script to strict mode:

    (function() { 
        'use strict';
    
       // your functions and code in here
    
    })(); 
    

    This will offer some protection from the scripts interfering with each other as all the variables and functions become isolated within the wrapped function - The "use strict" setting will highlight variable errors before code gets to them which will help in the long run.

    in terms of getting to the bottom of it, if you are getting the above error in the chrome developer tools. then click on the error and you will get sent to the compressed javascript file (which will be a pain). but if you click on the braces icon at the bottom of the script window.

    enter image description here

    Chrome will expand it out and it may give you a pointer as to where the problem lies.

  • Alex Brown 129 posts 620 karma points
    Mar 28, 2018 @ 08:44
    Alex Brown
    0

    Thanks for the tip Kevin, I didn't know Chrome had an unminifier! I ended up wrapping all my methods in IIFEs but with no luck.

    I ended up looking at line 5668 in DependencyHandler and seeing that my controller wasn't being included when hasOwnProperty() was called,

    I fixed this issue by removing the space in my folder "Size Guides", then removing the space from package.manifest and Dashboard.config.

    Looks like spaces are a no-no. Not sure why there was a space there in the first place! Cheers for the help.

Please Sign in or register to post replies

Write your reply to:

Draft