Uncaught TypeError: Cannot call method ‘replace’ of null (underscore.js:768)

Uncaught TypeError: Cannot call method ‘replace’ of null (underscore.js:768)

Cause

This error is throw when a Backbone View receive an invalid String as template, in template() function.

template: _.template($('.invalidSelector').html())

How to fix

  • Check the String is not null and not empty
  • If you are using jQuery, check the selector and the result of html()

More info Backbone View template() documentation