Неизвестная ошибка объекта шаблона с runbars 2.0 runtime

Я опубликовал весь свой код как runnable, который использует express для загрузки статического контента

Я предварительно скомпилировал этот шаблон handlebars:

 <img src="{{coverImage}}"/>
<ul>
    <li>{{title}}</li>
    <li>{{author}}</li>
    <li>{{releaseDate}}</li>
    <li>{{keywords}}</li>
</ul>

Удалить

Я получил эту функцию:

    (function() {
  var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {};
templates['bookTemplate'] = template(function (Handlebars,depth0,helpers,partials,data) {
  this.compilerInfo = [4,'>= 1.0.0'];
helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
  var buffer = "", stack1, helper, functionType="function", escapeExpression=this.escapeExpression;


  buffer += "<img src=\"";
  if (helper = helpers.coverImage) { stack1 = helper.call(depth0, {hash:{},data:data}); }
  else { helper = (depth0 && depth0.coverImage); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
  buffer += escapeExpression(stack1)
    + "\"/>\r\n    <ul>\r\n        <li>";
  if (helper = helpers.title) { stack1 = helper.call(depth0, {hash:{},data:data}); }
  else { helper = (depth0 && depth0.title); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
  buffer += escapeExpression(stack1)
    + "</li>\r\n        <li>";
  if (helper = helpers.author) { stack1 = helper.call(depth0, {hash:{},data:data}); }
  else { helper = (depth0 && depth0.author); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
  buffer += escapeExpression(stack1)
    + "</li>\r\n        <li>";
  if (helper = helpers.releaseDate) { stack1 = helper.call(depth0, {hash:{},data:data}); }
  else { helper = (depth0 && depth0.releaseDate); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
  buffer += escapeExpression(stack1)
    + "</li>\r\n        <li>";
  if (helper = helpers.keywords) { stack1 = helper.call(depth0, {hash:{},data:data}); }
  else { helper = (depth0 && depth0.keywords); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
  buffer += escapeExpression(stack1)
    + "</li>\r\n    </ul>\r\n<button class=\"delete\">Delete</button>";
  return buffer;
  });
})();

Я добавил следующие скрипты:

 <script src="js/lib/handlebars.runtime-v2.0.0.js"></script>
 <script src="js/templates.js"></script>

Я вижу в Chrome Dev Tools, что оба скрипта загружаются.

Однако, когда я использую его следующим образом:

 //inside a Backbone view
 template:Handlebars.templates.bookTemplate

Я получаю эту ошибку:

 Uncaught Error: Unknown template object: function handlebars.runtime-v2.0.0.js:455template handlebars.runtime-v2.0.0.js:455hb.template handlebars.runtime-v2.0.0.js:644(anonymous function) templates.js:3(anonymous function)

Я получаю эту ошибку в строке 455 в handlebars runtime @2.0.0 в функции template, после небольшой отладки обнаруживаю, что templateSpec является функцией, но templateSpec.main - undefined:

  //this function makes a call to templates['bookTemplate'] = template(function (Handlebars,depth0,helpers,partials,data) {...} in the `bookTemplate.js`
  function template(templateSpec, env) {
/* istanbul ignore next */
if (!env) {
  throw new Exception("No environment passed to template");
}
//error occurs here: 
if (!templateSpec || !templateSpec.main) {
  throw new Exception('Unkn own template object: ' + typeof templateSpec);
}
...

Кроме того, я обнаружил, что Handlebars.templates - пустой объект.

Что здесь происходит?

Ответы

Ответ 1

Если вы предварительно скомпилировали этот шаблон с помощью handlebars 1.3.x, вы столкнетесь с изменением с 2.0. Убедитесь, что на сервере/сборке запущен компилятор 2.0 руля.

Ответ 2

Вы уверены, что вы скомпилировали шаблон с той же версией Handlebars, что и среда выполнения?

Я просто пытаюсь использовать Handlebars 2.0, и мои скомпилированные шаблоны имеют [6,'>= 2.0.0'] в поле компилятора. Скомпилированный шаблон предполагает, что он был скомпилирован с помощью Handlebars 1.x.