title: How to use Handlebars with RequireJS
body: <p>I encountered the following error:</p>
  
  <pre class="lang-none prettyprint-override"><code>Uncaught TypeError: Cannot call method 'compile' of undefined.
  </code></pre>
  
  <p>RequireJS configuration:</p>
  
  <pre><code>requirejs.config({
      baseUrl: "resources",
      paths: {
          'app':'lib',
          'jquery': 'lib/jquery-1.9.1',
          'bootstrap': 'lib/bootstrap',
          'html5shiv': 'lib/html5shiv',
          'spin': 'lib/spin',
          'respond': 'lib/respond',
          'underscore': 'lib/underscore',
          'backbone': 'lib/backbone',
          'handlebars': 'lib/handlebars-v3.0.3',
          'template': 'app/templates'
      },
      shim: {
          html5shiv: {
              deps: ['jquery']
          },
          respond: {
              deps: ['jquery']
          },
          bootstrap: {
              deps: ['jquery']
          },
          jquery: {
              exports: '$'
          },
          underscore: {
              exports: '_'
          },
          backbone: {
              deps: ['jquery', 'underscore'],
              exports: 'Backbone'
          },
          handlebars: {
              exports: "Handlebars"
          }
      }
  });
  
  require([
      'jquery',
      'underscore',
      'backbone',
      'handlebars',
      'app/Router'
  ], function($,
              _,
              Backbone,
              Handlebars,
              Router) {
      var router = new Router();
      Backbone.history.start();
  });
  </code></pre>
  
  <p>View:</p>
  
  <pre><code>define([
    'backbone',
    'handlebars',
    'text!templates/mytemplate.html'
  ], function(Backbone, Handlebars, Template){
  
      MyView = Backbone.View.extend({
          tagName: 'li',
          template: Handlebars.compile(Template),
  
          render: function() {
              this.$el.html(this.template(this.model.toJSON()));
              return this;
          }
      });
  
      return MyView;
  });
  </code></pre>