HTMLBars in 1.10.0-beta.4 - template must be a function


#1

I know there are a lot of these reports around, but none of those are quite like this. I’m trying to upgrade a my 1.9 app to 1.10 beta. It’s a bit older app, so no common.js, require.js or ember-cli.

I get the aforementioned Assertion Failed: template must be a function. Did you mean to call Ember.Handlebars.compile("...") or specify templateName instead? error.

The problem is here (from ember.js source):

var useHTMLBars = false;
useHTMLBars = template.isHTMLBars;

if (useHTMLBars) {
	Ember.assert('template must be an object. Did you mean to call Ember.Handlebars.compile("...") or specify templateName instead?', typeof template === 'object');
	var env = Ember.merge(buildHTMLBarsDefaultEnv(), options);
	output = template.render(this, env, buffer.innerContextualElement(), this._blockArguments);
} else {
	Ember.assert('template must be a function. Did you mean to call Ember.Handlebars.compile("...") or specify templateName instead?', typeof template === 'function');
	output = template(context, options);
}

template.isHTMLBars is undefined. Here’s how template object looks in chrome tools:

I’m using grunt with grunt-ember-templates task. The precompiled templates it produces look something like this:

Ember.TEMPLATES["_layout"] = Ember.HTMLBars.template({"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) {
  var stack1, helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression, buffer = '';
  data.buffer.push(escapeExpression(((helpers.partial || (depth0 && depth0.partial) || helperMissing).call(depth0, "main_menu", {"name":"partial","hash":{},"hashTypes":{},"hashContexts":{},"types":["STRING"],"contexts":[depth0],"data":data}))));
 // SNIP, a bunch more of these
  return buffer;
},"useData":true});

I tried adding the suggested EmberENV switch, didn’t help. My starting output looks like this:

WARNING: FEATURE["ember-htmlbars"] is set as enabled, but FEATURE flags are only available in canary builds. ember.js:3956
DEBUG: -------------------------------
DEBUG: Ember  : 1.10.0-beta.4
DEBUG: jQuery : 1.11.0
DEBUG: ------------------------------- 

My best guess right now is that I need to plug in htmlbars.runtime somewhere. However, there are no downloads anywhere. I tried building from source, I get amd and common.js modules. I tried plugging those in (shimmed), but no change. It seems Ember.HTMLBars.template is there, so the runtime comes preloaded?

I really need help at this point. What am I doing wrong?


#2

The template is being precompiled with handlebars (not HTMLBars) by grunt-ember-templates.

You need to use the master version of grunt-ember-templates and specify some custom configuration to precompile peoperly. Take a look at https://github.com/dgeb/grunt-ember-templates/pull/77 for details.


#3

Thanks, I figured out that part. I’m still struggling with some custom helpers I have to rewrite. Once done, I’ll post more info how I got past this and (hopefully) got it working.


Upgrade to 1.10.0-beta lessons
#4

OK, I’m stuck again. Would it be OK to rename this thread into something like “Upgrading to 1.10 beta woes” :-)? Or should I start a new topic?