Ember.HTMLBars.compile is undefined in Ember 2.7

416 Views Asked by At

In our application we use the template compiler at runtime by calling Ember.HTMLBars.compile with a handlebars template. Example code:

let myTemplate = `{{foo}}`;
application.register(`template:my-template`, Ember.HTMLBars.compile(myTemplate));

I've tried to upgrade from Ember 2.6 to Ember 2.7 but I get the following error in the developer console if I try to compile the template:

_ember.default.HTMLBars.compile is not a function()

In the documentation I couldn't find anything about the compile method being removed from the HTMLBars compiler.

How can I still use/enable the HTMLBars compiler at runtime in my application?

3

There are 3 best solutions below

1
AHOYAHOY On BEST ANSWER

import original ember-template-compiler.js in ember-cli-build.js

app.import('bower_components/ember/ember-template-compiler.js');
1
apexpals.com On

Since there is less information provided, first try and check the error source.

presumably a library it is, you need to open your developers console [lets say chrome] and then click on the error which will direct you to where the error originates from so you can adjust or rectify the code...

0
Илья Лукьянов On

I was needed to compile template during runtime und used https://www.npmjs.com/package/ember-cli-handlebars-inline-precompile. Try this:

import hbs from 'htmlbars-inline-precompile';
application.register(`template:my-template`, hbs`{{foo}}`);