Updating to Ember 2.x application.lookup is not a function


#1

So I finally bit the bullet to update our production Ember app from 1.13.9 to 2.X and I’m already running into issues. Looking into the deprecation list, I changed out all my initializers to use application.lookup instead of container.lookup as per this doc http://emberjs.com/deprecations/v2.x/#toc_ember-applicationinstance-container

But I’ve been running into “application.lookup is not a function”. I’ve tried reinstalling ember but to no avail. It seems like a simple issue but I haven’t figure it out?

Code in question app/initializers/cleardata.js

export function clearStore( application ) {
  application.deferReadiness();
  // the following clears all guest content
  application.lookup('store:main').findAll('guest').then(function(data){
    let guests = data.get('content');
    for ( let i = 0; i < guests.length; i++ ) {
      guests[i].deleteRecord();
      guests[i].save(); }
  });
  application.advanceReadiness();
}
export default {
  name: 'cleardata',
  initialize: clearStore
};

Current build versions:

Ember : 2.5.1

Ember Data : 2.5.2

jQuery : 2.2.3

Ember Simple Auth : 1.0.0


#2

You want to move this to be an instance-initializer instead of an initializer. Everything else can stay the same, just change the file location.

https://guides.emberjs.com/v2.0.0/applications/initializers/#toc_application-instance-initializers


#3

Oh shoot, didn’t even realize there were two different types. Thanks! Saved me a lot of headache. Onto the next deprecation :fearful: