Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 938
Tom Brunoli Avatar asked Nov 04 '22 08:11

Tom Brunoli


1 Answers

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);
like image 162
monkeyboy Avatar answered Nov 08 '22 06:11

monkeyboy