Tom Brunoli
Tom Brunoli

Reputation: 3466

require-handlebars-plugin build error - ReferenceError: _ is not defined

I'm trying to build a requirejs/backbone/handlebars project, and I seem to be coming accross this error when I try run the app.build.js:

Tracing dependencies for: main
ReferenceError: _ is not defined
In module tree:
    main
      cs
        hbs
          underscore

ReferenceError: _ is not defined
In module tree:
    main
      cs
        hbs
          underscore

    at Object.eval (eval at <anonymous> (/usr/local/share/npm/lib/node_modules/requirejs/bin/r.js:13718:64))

The app works perfectly in and without errors when not built. The project has backbone and underscore included as requirejs shims if it matters. I would post the whole source, but it is an internal system, so I can't. If more info is needed, I can post it.

Thanks!

Upvotes: 5

Views: 1133

Answers (1)

monkeyboy
monkeyboy

Reputation: 542

I had the same problem and this worked for me -

Remove underscore from your RequireJS shim.

Then at the bottom of your underscore.js file, just above the closing brackets and call statement, add a define statement to properly export _

  define(function(){
        return _;
    });

}).call(this);

Upvotes: 2

Related Questions