Search code examples
ember.jsember-cli

Ember.js - Getting App instance in module


I have to port a non-cli project to the cli. I have a route that is:

App.thisRoute = App.previouslyDefinedRoute.extend({...})

With the CLI, I've tried this:

// routes/thisRoute.js
import App from 'app';

export default App.previouslyDefinedRoute.extend({...})

That gives me this Ember Inspector Error:

Ember Inspector has errored.

...

Error message: Could not find module app imported from app/routes/thisRoute

I've also tried:

// routes/thisRoute.js
import App from 'routes/previouslyDefinedRoute.js';

export default App.previouslyDefinedRoute.extend({...})

Both dont work.

How do I get my app instance?


Solution

  • There is no app instance in ember-cli, it uses ES6 modules instead, in order to extend a route you will have to import it first.

    import PreviousRoute from 'yourProjectName/routes/previouslyDefinedRoute';

    Note that the file extension is not needed.

    And then you can just export default PreviousRoute.extend({});.

    Your files must always export either a default or a named function in order to be used by other files.