2

I'm using RequireJS with the text plugin for my HTML-templates.

define(
  [
    'text!./../../templates/twitterTemplate.html',
    'jquery',
    'underscore',
    'backbone'
  ],

  function(twitterTemplate, $, _, Backbone) {

    var compiled = _.template(twitterTemplate);

    return Backbone.View.extend({
      el: '#tweets',

      render: function() {
        this.$el.append(compiled(this.model));

        return this;
      }
    });
  }
);

Everything works fine when running in a browser. But when I run my jasmine-tests from Node.js, I get the following error when Node.js require is trying to load the twitterTemplate.html file:

(function (exports, require, module, __filename, __dirname) { <h4><%= title %>
                                                              ^
   Message:
     SyntaxError: Unexpected token <
   Stacktrace:
     SyntaxError: Unexpected token <
    at Module._compile (module.js:437:25)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:362:17)

I've probably misunderstood something. Grateful for answers that helps me solve this issue.

Thanks!

nekman
  • 1,919
  • 2
  • 15
  • 26
  • Are you intentionally feeding an AMD module to CommonJS-only require within NodeJS? I haven't heard of NodeJS's require understanding AMD modules. – ddotsenko Feb 13 '13 at 05:08
  • Yes I do. So it isn't possible for me to handle text-dependencies from CommonJS-only require? Do I need to use a UMD-pattern? – nekman Feb 13 '13 at 18:04
  • I am rather involved into AMD community, and am tangentially overseeing the CJS side. I heard that CommonJS guys were **talking** about plugins spec, but i never saw it materialize. In other words, I would not expect a reliable native way to load plugins or AMD modules in Node. However, check this out: [RequireJS adapter for Node.js](http://requirejs.org/docs/node.html) – ddotsenko Feb 14 '13 at 07:44

0 Answers0