3

I am using ember-cli and have a problem with selecting the production environment. Specifically, everything works when I run ember serve --environment=development and I get a blank page when I run ember serve --environment=production. In the console, I see:

  • Uncaught TypeError: undefined is not a function
  • Uncaught Error: Could not find module simple-auth/authenticators/base

All other things are equal, and all dependencies are up to date. I'm a total noob so I don't even know where to begin on how to debug: is it ember? ember-cli? broccoli? Any help would be appreciated.

dbinetti
  • 215
  • 3
  • 9
  • This is not ember-cli failing, this is broccoli failing to build because A) You are referencing an undefined function in your code. B) Referencing simple-auth/authenticators/base incorrectly. – James_1x0 Jul 29 '14 at 15:57
  • Here is the way to modify Brocfile.js: http://stackoverflow.com/a/26292079/1173020 – denis.peplin Oct 10 '14 at 04:54

2 Answers2

5

I had exact the same problem, and James_1x0 is correct, it is an broccoli issue. After debugging it occurs, that the "undefined" error apears on "Ember.handlebars.compile" which lead to other research. It seems, that in production envrironment "handlebars.js" is replaced by "handlebars.runtime.js" in the ember-cli build process, which seem to be a problem for broccoli at this time.

Other devs had the same problem but with other libraries as well: https://github.com/stefanpenner/ember-cli/pull/675#issuecomment-47431195

Here the solution was to add:

    var index = app.legacyFilesToAppend.indexOf('bower_components/handlebars/handlebars.runtime.js');
if(index) {
    app.legacyFilesToAppend[index] = 'bower_components/handlebars/handlebars.js';
}

into your Brocfile.js to replace the "handlebars.runtime.js" with the "handlebars.js". This also fixed the problem for me. It sure has the drawback that the whole handlebars file is deployed but its a workarround for now, until the problem is fixed.

0

Solution is mentioned on Ember CLI website:

This is somewhat non-standard and discouraged, but suppose that due to a requirement in your application that you need to use the full version of Handlebars even in the production environment.

Basically, you can pass vendorFiles option to your EmberApp instance which will force CLI to include full version of Handlebars.

Example of explicitly requiring handlebars.js , in Brocfile.js:

var app = new EmberApp({
  vendorFiles: {
    'handlebars.js': {
      production: 'bower_components/handlebars/handlebars.js'
    }
  }
});

This is recommended way of solving this issue(discussion on GitHub).

Josh Tumath
  • 135
  • 1
  • 13
Daniel Kmak
  • 18,164
  • 7
  • 66
  • 89