jhamm
jhamm

Reputation: 25032

Why won't my Handlebar lib load? - Requirejs

I am trying to use the requirejs-hbs lib in a Backbone project. I have the Handlebars lib and the requirejs-hbs lib in the same folder. They are declared the same in my config. When I look at the sources in my chrome tab, I am only getting the require-hbs script, I am not getting the handlebars script. Here is my config file:

require.config({
  hbs: {
    templateExtension: '.hbs'
  },
  paths: {
    backbone: "libs/backbone/backbone",
    Handlebars: 'libs/handlebars/handlebars.amd',
    hbs: 'libs/requirejs-hbs/hbs',
    jquery: 'libs/jquery/jquery',
    underscore: 'libs/underscore/underscore'
  },
  shim: {
    backbone: {
      deps: [
        'underscore',
        'jquery'
      ],
      exports: 'Backbone'
    },
    underscore: {
      exports: '_'
    }
  }
});

require(['js/router/easier.view'], function(View) {
  'use strict';

  var view = new View();
});

And here is the view where I am trying to access my template.

define(function(require) {
  'use strict';

  var Backbone = require('backbone');
  var testTemplate = require('hbs!views/test.hbs');

  var router = Backbone.View.extend({
    render: function() {
      debugger;
    }
  });

  return router;
});

The error I get is GET http://localhost:9000/handlebars.js 404 (Not Found). I have the other files that I am declaring, but I do not have the handlebars.js. What am I doing wrong?

Upvotes: 0

Views: 186

Answers (1)

sQVe
sQVe

Reputation: 2015

You are creating a path to Handlebars but if you look at the source of requirejs-hbs you see that it uses handlebars.

So either change the requirejs-hbs source to Handlebars or change your path to handlebars.

Should work.

Upvotes: 1

Related Questions