gruntjs/grunt-contrib-handlebars

Uncaught TypeError: Object #<Object> has no method 'merge'

Closed this issue · 9 comments

For some reason this merge method doesn't exist
helpers = this.merge(helpers, Handlebars.helpers);

When I do a console.log(this) in the compiled javascript I get an object but can't find the merge within it's own property or in the prototypical chain.
I'm sure this is a versioning problem with handlebars.js and handlebars.runtime.js
I was using v0.5.4 with handlebars 1.0.0-rc.4

Just experienced the same thing on a new project.

node 0.10.7
grunt 0.4.1
grunt-contrib-handlebars 0.5.9
handlebars 1.0.0-rc.4 (via Bower)

UPDATE: I tried grabbing the latest handlebars (1.0.0) from the website and it worked.

After a little digging, it looks like the problem is caused by Handlebars 1.0.12. When I set the version to 1.0.11, it works. So the issue (sort of) is this package's reliance on "handlebars": "~1.0.10", which pulls down 1.0.12. Ultimately, this seems like a Handlebars issue though, not really something wrong with this package.

UPDATE 2: According to this issue, 1.0.0 is required to use the 1.0.12 build.

We had the same issue. We pulled the runtime from the handlebars site and it was working again.

Hi!

We were experiencing the same.
Via npm shrinkwrap we were able to force grunt-contrib-handlebars to use handlebars 1.0.10 instead of 1.0.12.

Hi, same thing happend to us, we fixed it using @KK-MarcelJahn solution.

The 1.0.0 runtime is required to use pre-compiled templates with built with 1.0.12. If you're having issues, update your client side version.

@w33ble Updating the client-side when you output as an npm module for, say, browserify, makes absolutely no difference whatsoever. The require statement in the output templates.js file still says require('handlebars'); when options: node === true.

I can confirm that this issue is not fixed.

For reference, here is my handlebars grunt config:

    handlebars:
      main:
        options:
          wrapped: true
          namespace: 'com.banno.clientlib.templates'
          node: true
          processName: (filename) ->
            filenameRegex = ///(?:.*/)*(.*)(?:\.handlebars$)///
            filenameRegex.exec(filename)[1]
        files: [
          src:
            [
              'src/main/handlebars/*.handlebars'
              'src/main/handlebars/**/*.handlebars'
              'src/main/handlebars/**/**/*.handlebars'
              'src/main/handlebars/**/**/**/*.handlebars'
            ]
          dest:
            'dist/templates.js'
        ]

I use browserify to build my applications. It walks the require tree and creates a nice wrapped environment for you so that your application can be completely modular in the browser without using an external loader.

So when require is called, the version of handlebars included in the grunt-contrib-handlebars package matters. I attempted to fix this by using node-handlebars-runtime@1.0.12 However, there is still a problem, because grunt-contrib-handlebars isn't including the modular handlebars runtime. Any help is appreciated.

I haven't used browserify before, so I don't know what the issue would be. I suspect that it's not a problem with the grunt plugin, but I could be wrong. According to the issue that was opened in handlebars (see above), they only test things against the packaged versions. In this case, 1.0.12 and 1.0.0 (final). If you mix a match, things will probably break, as they did here.

Maybe opening an issue in the handlebars repo would shed some light on your issue?

The issue is in the handlebars bower component repo. It's still referenccing old dependency versions. Sent a pull request to fix it.

@w33ble – Updating the runtime to 1.0.0 did the trick. Thanks!