You call require string literal. When you call require as follows, it acts in pseudo-synchronous mode . It acts like a synchronous call because it will immediately return the module. It is pseudo-synchronous because the module must be loaded before you call the pseudo- require form.
So you can do this:
define(['backbone', 'underscore', 'jquery', 'text!templates/bookTemplate.html'], function (Backbone, _, $) { var bt = require('text!templates/bookTemplate.html');
and this will work because the module will be loaded before require executed. Or you can use the method that you specified in the second code snippet:
define(['backbone', 'underscore', 'jquery', 'text!templates/bookTemplate.html'], function (Backbone, _, $, bt) {
Or you can use the CommonJS wrapper:
define(function(require, exports, module) { var Backbone = require('backbone'); var _ = require('underscore'); var jquery = require('jquery'); var bt = require('text!templates/bookTemplate.html');
This wrapper works because RequireJS converts it at runtime to:
define(["require", "exports", "module", "backbone", "underscore", "jquery", "text!templates/bookTemplate.html"], function(require, exports, module) { var Backbone = require('backbone'); var _ = require('underscore'); var jquery = require('jquery'); var bt = require('text!templates/bookTemplate.html');
before executing the module.