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 'apply' of undefined" when handlebars version > 4.6.0 #1639

Closed
ivakarlec opened this issue Jan 13, 2020 · 5 comments

Comments

@ivakarlec
Copy link

After the release of handlebars@4.6.0 (2nd week of January 2020) I get a "TypeError: Cannot read property 'apply' of undefined":
{code}
TypeError: Cannot read property 'apply' of undefined
at Object.wrapper (/myProject/node_modules/handlebars/lib/handlebars/internal/wrapHelper.js:5:19)
at Object.eval (eval at createFunctionContext (/myProject/node_modules/handlebars/lib/handlebars/compiler/javascript-compiler.js:260:23), :13:196)
at main (/myProject/node_modules/handlebars/lib/handlebars/runtime.js:230:22)
at ret (/myProject/node_modules/handlebars/lib/handlebars/runtime.js:250:12)
at ret (/myProject/node_modules/handlebars/lib/handlebars/compiler/compiler.js:548:21)
at Object.invokePartial (/myProject/node_modules/handlebars/lib/handlebars/runtime.js:405:12)
at Object.invokePartialWrapper [as invokePartial] (/myProject/node_modules/handlebars/lib/handlebars/runtime.js:82:39)
at Object.eval (eval at createFunctionContext (/myProject/node_modules/handlebars/lib/handlebars/compiler/javascript-compiler.js:260:23), :15:28)
at main (/myProject/node_modules/handlebars/lib/handlebars/runtime.js:230:22)
at ret (/myProject/node_modules/handlebars/lib/handlebars/runtime.js:250:12)
at ret (/myProject/node_modules/handlebars/lib/handlebars/compiler/compiler.js:548:21)
at ExpressHandlebars._renderTemplate (/myProject/node_modules/express-handlebars/lib/express-handlebars.js:250:12)
at ExpressHandlebars. (/myProject/node_modules/express-handlebars/lib/express-handlebars.js:173:21)
{code}
There are some breaking changes in the handlebars@4.6.0 release: 770d746

@ivakarlec
Copy link
Author

Sorry, it's more likely an issue for express-handlebars...

@nknapp
Copy link
Collaborator

nknapp commented Jan 13, 2020

Please add details.

The function in your stack trace is new. It may be a problem here.

@nknapp nknapp reopened this Jan 13, 2020
nknapp added a commit that referenced this issue Jan 13, 2020
- helpers should always be a function, but in #1639 one seems to
  be undefined. This was not a problem before 4.6 because helpers
  weren't wrapped then.
  Now, we must take care only to wrap helpers (when adding
  the "lookupProperty" function to the options), if they
  are really functions.
@nknapp
Copy link
Collaborator

nknapp commented Jan 13, 2020

This issue should be fixed in Handlebars 4.7.2.

@nknapp nknapp closed this as completed Jan 13, 2020
@MatYRicS
Copy link

This issue should be fixed in Handlebars 4.7.2.

It dosen't work for me with v. 4.7.2.

This is my helper file

module.exports = {
    truncate: function (str, num) {
        if (str.length <= num) {
            return str
        }
        return str.slice(0, num) + '...'
    }
};

And adding this to my app.js file:

const truncate = require('./helpers/hbs')

const hbs = exphbs.create({
    helpers: truncate
});

And this is how I use the function in my handlebars file:

            <tbody>
                {{#each systems}}
                <tr>
                    <td class="text-center">{{#each this}} {{ truncate name 10 }} {{/each}} </td>
                    <td class="text-center">{{#each this}} {{table}} {{/each}}</td>
                    <td class="text-center">
                        <button type="button" class="ikon ikon-rundt ikon-rediger" title="Rediger"></button>
                        <button type="button" class="ikon ikon-rundt ikon-slet" title="Slet"></button>
                    </td>
                </tr
...

I keep getting:
TypeError: Cannot read property 'length' of undefined

@nknapp
Copy link
Collaborator

nknapp commented Jan 27, 2020

It's a different problem (differen error message). Please have a look if it is related to #1642
Otherwise open a new issue, please also provide the template-input there (i.e. the parameter to "res.render(...")

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

3 participants