I have an app that utilizes Backbone.js. Everything was working fine, but recently I added RequireJS to my project, and that of course made everything break, so I'm in the processes of defining my dependencies and making everything work again.
The error I'm getting is Uncaught ReferenceError: JST is not defined.
I have the following CoffeeScript view file. Note the JST line:
define ["app"], (App) ->
Snip.Views.Appointments ||= {}
class Snip.Views.Appointments.IndexView extends Backbone.View
template: JST["backbone/templates/appointments/index"]
initialize: () ->
@options.appointments.bind('reset', @addAll)
addAll: () =>
@options.appointments.each(@addOne)
addOne: (appointment) =>
view = new Snip.Views.Appointments.AppointmentView({model : appointment})
@$("ul").append(view.render().el)
My "app" dependency itself has Backbone and Underscore as dependencies, so I don't think the problem is that Backbone is not present:
define ["underscore", "backbone"], (_, Backbone) ->
window.Snip =
Models: {}
Collections: {}
Routers: {}
Views: {}
When I load the page, I get Uncaught ReferenceError: JST is not defined.
What do I need to do to get my script to know about JST?
Edit: here are my paths and stuff
require
paths:
jquery: "jquery-1.7.2.min"
underscore: "lodash.min"
appointment: "backbone/models/appointment"
appointmentIndexView: "backbone/views/appointments/index_view"
appointmentsRouter: "backbone/routers/appointments_router"
relational: "backbone-relational"
shim:
"underscore":
exports: "_"
"backbone":
deps: ["underscore", "jquery"]
exports: "Backbone"
"relational":
deps: ["backbone"]
requirejs ["appointmentsRouter"], (AppointmentsRouter) ->
window.router = new Snip.Routers.AppointmentsRouter({appointments: []})
Backbone.history.start()
there is no variable called
JSTavailable when the module in question is loaded.You need to add the path to your JST -library to the
paths-attribute inrequire.config.Then most likely you'll need to add it to
shimalso and make it exportJST.In require.js your alarm bells should start ringing when you use some external resource inside a module that has not been
A. Imported in the
define-section of that moduleB. Imported via
requireinside that moduleC. Mentioned in your
require.config-functionUPDATE
You need to make a new module (like templates.js), that returns a variable (for example
JST).Then in the module you want to use those templates in: