Can't resolve dependency "epi.globalcommandregistry" when setting up a custom command

Member since: 2004

I have the following javascript in the file ClientResources/Scripts/widgets/media/Mediacommands.js:

require(['dojo/aspect', 'epi/dependency', 'samples/media/MediaUpdateCommand'], function (aspect, dependency, MediaUpdateCommand) {

    var handle,
		key = 'epi.cms.globalToolbar',
		registry = dependency.resolve('epi.globalcommandregistry'),
		callback = function (identifier, provider) {
		    if (identifier !== key) {

		    provider.addCommand(new MediaUpdateCommand(), {
		        showLabel: true


    handle = aspect.after(registry, 'registerProvider', callback, true);

My module.config looks like this:

        <add assembly="JR.Web.CMS" />
        <add name="epi-cms.widgets.base" path="Styles/Styles.css" resourceType="Style"/>
        <add name="epi-cms.widgets.base" path="Scripts/widgets/media/MediaCommands.js" resourceType="Script"/>
      <add name="samples" path="Scripts/widgets" />
    <add dependency="Shell" />

This is intended to add a button to the Editor toolbar, and *sometimes* works. However around 70% of the time I see the error Can't resolve dependency "epi.globalcommandregistry" in the console.

This corresponds to the line registry = dependency.resolve('epi.globalcommandregistry'), in the javascript above.

Is there any reason why the dependency can't be resolved at some times and more to the point, how can I ensure it's resolved every time?



#119097 Mar 20, 2015 15:51
  • Member since: 2002


    I suggest that you create an init module on the client since this will make the code run at the right time. Here is a copy paste example from something I worked on recently:


    <clientModule initializer="[your module class including namespace]">
    <add dependency="CMS" type="Require RunAfter" />

    Client module sample:

        // Pull in the patches. Not used here, just evaluated, since this is the first module loaded when starting the application.
    function (
    ) {
        return declare([_Module], {
            // summary:
            //		Template module implementation.
            // tags:
            //      internal
            _settings: null,
            constructor: function (settings) {
                this._settings = settings;
            initialize: function () {
                var commandregistry = dependency.resolve("epi.globalcommandregistry");
                //We need to wait for the viewsettings to initialized before creating the global toolbar command provider
                commandregistry.registerProvider("epi.cms.globalToolbar", new AddItemFromTemplateCommandProvider({templatesRoot : this._settings.templatesRoot}));

    #119233 Mar 25, 2015 8:22
  • Member since: 2004


    That did it for me (specifically the module.config settings) - thanks!.

    #119583 Mar 30, 2015 12:57