0
votes

I am building an Ember-cli app using the Simple-Auth library. The current system setup is basic with only an initializer instantiated in the initializers folder. The name of the initializer is

/*initializers/initializer-application.js*/

var ApplicationInitializer = Ember.Application.initializer({
    name: 'authentication',
    initialize: function(container, application) {
        Ember.SimpleAuth.setup(container, application);
    }
});

export default ApplicationInitializer;

The error is returning Cannot read property 'name' of undefined

Update Trace

Uncaught TypeError: Cannot read property 'name' of undefined commandcenter.js:54876
Ember.Application.reopenClass.initializer commandcenter.js:54876
(anonymous function) commandcenter.js:58229
default commandcenter.js:58226
(anonymous function) commandcenter.js:110
requireModule commandcenter.js:54
(anonymous function)

Thanks for the help, if more information needed, will definitely supply.

Update 2

;(function() {
define("ember/load-initializers",
  [],
  function() {
    "use strict";

    return {
      'default': function(app, prefix) {
        var initializersRegExp = new RegExp('^' + prefix + '/initializers');

        Ember.keys(requirejs._eak_seen).filter(function(key) {
          return initializersRegExp.test(key);
        }).forEach(function(moduleName) {
          var module = require(moduleName, null, null, true);
          if (!module) { throw new Error(moduleName + ' must export an initializer.'); }
          app.initializer(module['default']);
        });
      }
    }
  }
);
})();


var module = require(moduleName, null, null, true);
//Is returning module.default = undefined 
1

1 Answers

2
votes

Ember.Application.initializer is the actual function that performs the initialization ie it won't return an Initializer object - in fact it returns undefined (there's no Initializer class in Ember anyway).

Export the raw object instead:

/*initializers/initializer-application.js*/

export default {
    name: 'authentication',
    initialize: function(container, application) {
        Ember.SimpleAuth.setup(container, application);
    }
};

Also check ember-load-initializers.js:

...
    }).forEach(function(moduleName) {
      var module = require(moduleName, null, null, true);
      if (!module) { throw new Error(moduleName + ' must export an initializer.'); }
      app.initializer(module['default']); /**this is where the initializer is actually run**/
    });
...