Ember-cli creates/initializes app.js twice

268 views Asked by At

I'm moving my project from Ember AppKit to Ember-Cli. I have an myapp/app/app.js, where the app is initialized and in myapp/app/index.html I have the following lines:

        var config = require('myapp/config/environment')['default'];
        window.App = require('myapp/app')["default"].create(config.APP);

*config is not that important in my question.

So when I run the ember server I see that app.js was called twice. For the first time, automatically, I guess, and the second call is made by create() function from above. So after running the server I get an error:

"Uncaught Error: Assertion Failed: You cannot use the same root element (body) multiple times in an Ember.Application "

I know that the error means that I'm creating two instances of my app in the same DOM-Object and it can be solved by creating two sub containers () with different ids.

But how do I avoid creating the first instance, which is done automatically, before I actually call create()? Without the lines shown above the app is not shown at all, but with them I get the mentioned error. I have checked the whole app implementation, there is nothing what would call the initial instance creation, before create() function from above.

I didn't have that mistake in EmberAppKit running Grunt

2

There are 2 answers

3
Sam Selikoff On

In Ember CLI config lives in /config/environment.js, and it will be handed to your app automatically. You shouldn't need to this manually.

0
vtm On

Setting window.App=this in app.js has solved the problem.

If you look into my-app.js in assets, you will see that an instance is created at the end of the script. So it only has to be assigned to window.App