4
paths: {
          jquery: 'libs/jquery/jquery-min',
          underscore: 'libs/underscore/underscore-min',
          backbone: 'libs/backbone/backbone-optamd3-min',
          handlebars: 'libs/handlebars/handlebars',
          text: 'libs/require/text'
      }

   define([
      'jquery',
       'underscore',
       'backbone',
       'collections/todos',
       'views/todos',
       'text!templates/stats.html',
       'common',
       'handlebars'
  ], function ($, _, Backbone, Todos, TodoView, statsTemplate, Common, handlebars) {
   //handlebars is null
   console.log("handlebars is",handlebars);

})

Except handlebars,others can load successfully.Why and how to make handlbars load successfully.thanks

FruitBreak
  • 570
  • 1
  • 7
  • 19
shawnXiao
  • 850
  • 3
  • 9
  • 16
  • we should wrap the handlebars in another file. And the require in main.js handlebars-wrap.js define([js/libs/handlebars/handlebars], function () { return Handlebars; }); main.js require.config({ path: { handlebars:'libs/handlebars/handlebars-wrap' } }); – shawnXiao Aug 08 '12 at 15:44

1 Answers1

30

Firstly, I can see that you're new but please try to add more detail to your question to help others help you.

From glancing at the source I don't think Handlebars is compatible with AMD, therefore you will need to shim it yourself. Something like this:

requirejs.config({
    shim: {
        'handlebars': {
            exports: 'Handlebars'
        }
    }
});
Simon Smith
  • 8,024
  • 2
  • 30
  • 40
  • Thanks...There is also another methord to solve the problem.We should wrap the Handlebars in another file. and require it . – shawnXiao Aug 11 '12 at 14:28
  • how do you load the precompiled templates? – chovy Apr 21 '13 at 07:14
  • 1
    @shawnXiao, how is that? – Rubens Mariuzzo Nov 11 '13 at 17:15
  • Thank you Sir! I have been dealing with this (what I thought was a) bug all morning and afternoon. I searched and searched about compatibility and got nothing until your post. I know I can only like your answer once but I clicked like more than a dozen times because its the thought that counts. – RachelD Apr 23 '14 at 21:00
  • This was very helpful for me in development, but now that I'm building and optimizing my app with r.js, I'm getting the same error, even though I'm using the same config file and same shim configuration. Is there any reason this wouldn't work with r.js? – David Biehl Jun 03 '14 at 21:22