Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot read property '0' of undefined #1250

Closed
adamreisnz opened this issue Sep 7, 2016 · 10 comments
Closed

TypeError: Cannot read property '0' of undefined #1250

adamreisnz opened this issue Sep 7, 2016 · 10 comments

Comments

@adamreisnz
Copy link

adamreisnz commented Sep 7, 2016

I get the following error when using {{#unless @last}}<br>{{/unless}} in an each block inside of a table structure, e.g.

<table class="AddressTable">
    <tr>
      <td>
        <strong>Factuuradres</strong><br>
        {{customer.name}}<br>
        {{#each customer.address.parts as |part|}}
          {{part}}{{#unless @last}}<br>{{/unless}}
        {{/each}}
      </td>
      <td>
        {{#unless order.isPickUp}}
        <strong>Bezorgadres</strong><br>
        {{#if order.delivery.companyName}}
          {{order.delivery.companyName}}<br>
        {{/if}}
        {{order.delivery.name}}<br>
        {{#each order.delivery.address.parts as |part|}}
          {{part}}{{#unless @last}}<br>{{/unless}}
        {{/each}}
        {{/unless}}
      </td>
    </tr>
  </table>

When I move the whole unless block out of the table, it works fine. If I wrap the unless block in an additional <p> tag inside of the '`, it also works. What's happening here?

TypeError: Cannot read property '0' of undefined
    at eval (eval at createFunctionContext (node_modules/handlebars/dist/cjs/handlebars/compiler/javascript-compiler.js:254:23), <anonymous>:6:62)
    at prog (node_modules/handlebars/dist/cjs/handlebars/runtime.js:219:12)
    at execIteration (node_modules/handlebars/dist/cjs/handlebars/helpers/each.js:51:19)
    at Object.<anonymous> (node_modules/handlebars/dist/cjs/handlebars/helpers/each.js:61:13)
    at eval (eval at createFunctionContext (node_modules/handlebars/dist/cjs/handlebars/compiler/javascript-compiler.js:254:23), <anonymous>:10:31)
    at Object.prog [as inverse] (node_modules/handlebars/dist/cjs/handlebars/runtime.js:219:12)
    at Object.<anonymous> (node_modules/handlebars/dist/cjs/handlebars/helpers/if.js:17:22)
    at Object.<anonymous> (node_modules/handlebars/dist/cjs/handlebars/helpers/if.js:24:35)
    at Object.eval (eval at createFunctionContext (node_modules/handlebars/dist/cjs/handlebars/compiler/javascript-compiler.js:254:23), <anonymous>:20:33)
    at main (node_modules/handlebars/dist/cjs/handlebars/runtime.js:173:32)
    at ret (node_modules/handlebars/dist/cjs/handlebars/runtime.js:176:12)
    at ret (node_modules/handlebars/dist/cjs/handlebars/compiler/compiler.js:525:21)

This is with 4.0.5 on Node 6.5.0

@adamreisnz
Copy link
Author

adamreisnz commented Sep 7, 2016

It also barks with the same error when I move it all to a <div> structure as follows:

<div class="AddressTable">
    <p>
      <strong>Factuuradres</strong><br>
      {{customer.name}}<br>
      {{#each customer.address.parts as |part|}}
        {{part}}{{#unless @last}}<br>{{/unless}}
      {{/each}}
    </p>
    <p>
      {{#unless order.isPickUp}}
      <strong>Bezorgadres</strong><br>
      {{#if order.delivery.companyName}}
        {{order.delivery.companyName}}<br>
      {{/if}}
      {{order.delivery.name}}<br>
      {{#each order.delivery.address.parts as |part|}}
        {{part}}{{#unless @last}}<br>{{/unless}}
      {{/each}}
      {{/unless}}
    </p>
  </div>

@nikjuice
Copy link

nikjuice commented Oct 14, 2016

I have the same issue in my complex template. And I have found that in most cases this issue occurs when I have the "each" variable (in you case it is "part", named the same in at least 2 each cycles. Just try to change "part" in the second for each to something unique like "part2" or "item".

I can't push a template here, because it very big, but here are some part of stack where problem occurs

+ "\">\n " + container.escapeExpression((helpers.split || (depth0 && depth0.split) || helpers.helperMissing).call(depth0 != null ? depth0 : {},((stack1 = blockParams[0][0]) != null ? stack1.value : stack1),":",0,{"name":"split","hash":{},"data":data,"blockParams":blockParams})) + " (" + container.escapeExpression(container.lambda(((stack1 = blockParams[0][0]) != null ? stack1.count : stack1), depth0)) + ")\n </option>\n";

blockParams is undefined

@adamreisnz
Copy link
Author

Interesting, I'll give it a try, thanks.

@nikjuice
Copy link

Looks like that #1187 this pull request fix the problem!
I have updated handlebar to the latest version http://builds.handlebarsjs.com.s3.amazonaws.com/handlebars-latest.js and the issue is not reproducible any more

@nknapp
Copy link
Collaborator

nknapp commented Dec 30, 2016

@adamreisnz @olehyermokhin Since #1187 is part of 4.0.6, this should be fixed. Can you verify that? Would be great if we could close the issue.

@adamreisnz
Copy link
Author

Have re-tested with the HTML structure as I had posted above and it seems to work ok now with 4.0.6 🎉

@nknapp
Copy link
Collaborator

nknapp commented Dec 31, 2016 via email

@nikjuice
Copy link

nikjuice commented Apr 5, 2017

I'm sorry for late feedback. I can also confirm that it works with 4.0.6. Thanks a lot!

@jneuendorf
Copy link

The latest release is v4.0.5 (20 Nov 16). Why is v4.0.6 behind? If I do the upgrade from v4.0.5 to v4.0.6 are there any missing features or different bugs?

@nknapp
Copy link
Collaborator

nknapp commented Apr 10, 2017

There actually is a 4.0.6, but it's not available from all source. And there are some issues with it.
Have a look at #1312. It contains a list of bugs that would be fixed with 4.0.7.

I'm currently talking to @wycats in order to get the necessary access rights to perform a release myself. Once I have them (and the necessary time), I want to publish 4.0.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants