Missing Helper issue

  • I'm having some issues after upgrading from v2 to v3 involving the xlsx recipe. I am using a setup involving jsreport-core, jsreport-handlebars, and jsreport-assets. The error I'm getting:

    Error: Missing helper: "xlsxTableSheet"
    at Object.<anonymous> (C:\Projects2\cmd_api\node_modules\handlebars\dist\cjs\handlebars\helpers\helper-missing.js:19:13)
    at Object.wrapper (C:\Projects2\cmd_api\node_modules\handlebars\dist\cjs\handlebars\internal\wrapHelper.js:15:19)
    at eval (eval at compile (C:\Projects2\cmd_api\node_modules@jsreport\jsreport-handlebars\lib\handlebarsEngine.js:35:30), <anonymous>:11:133)
    at Object.main (eval at compile (C:\Projects2\cmd_api\node_modules@jsreport\jsreport-handlebars\lib\handlebarsEngine.js:35:30), <anonymous>:19:4)
    at C:\Projects2\cmd_api\node_modules@jsreport\jsreport-handlebars\async-helpers\index.js:61:22
    at ret (C:\Projects2\cmd_api\node_modules\handlebars\dist\cjs\handlebars\runtime.js:212:12)
    at Object.execute (C:\Projects2\cmd_api\node_modules@jsreport\jsreport-handlebars\lib\handlebarsEngine.js:80:14)
    at Object.execute (C:\Projects2\cmd_api\node_modules@jsreport\jsreport-handlebars\lib\worker.js:27:43)
    at executionFn (C:\Projects2\cmd_api\node_modules@jsreport\jsreport-core\lib\worker\render\executeEngine.js:216:40)
    at sandbox.js:16:18

    I've looked around on the forums/github/stackoverflow and have run out of potential solutions, but have garnered a better understanding of what may be causing the issue. Before rendering the template object with jsreport, it looks like this:

    engine: 'handlebars',
    recipe: 'xlsx',
    content: '{{!-- Resize and fill table --}}\r\n' +
    '{{xlsxTableSheet "Data" headers rows}}\r\n' +
    '{{xlsxWrapText}}\r\n' +
    '\r\n' +
    '{{!-- Enforces recalculation of formula cells when file is opened --}}\r\n' +
    '{{xlsxCalcOnLoad 1}}\r\n' +
    '\r\n' +
    '{{!-- Generates the spreadsheet --}}\r\n' +
    helpers: ';(function (global) {\r\n' +
    '\r\n' +
    " const path = require('path');\r\n" +
    ' require(path.resolve(__rootDirectory, "reports/helpers/xlsx"))(global);\r\n' +
    ' require(path.resolve(__rootDirectory, "reports/helpers/math"))(global);\r\n' +
    ' require(path.resolve(__rootDirectory, "reports/helpers/util"))(global);\r\n' +
    '\r\n' +
    ' // additional functions\r\n' +
    '\r\n' +
    ' Object.assign(global, {\r\n' +
    ' // additional functions\r\n' +
    ' });\r\n' +
    ' \r\n' +
    xlsx: { templateAsset: [Object] }

    When I tried hard coding the helpers instead of requiring them as I am above it worked correctly, leading me to believe that the render function is having trouble parsing the 'require' statements within the imported file. The helper files listed have a rough structure as follows:

    module.exports = function (global) {
    ....functions listed here

    Object.assign(global, {
    functions aliased here

    This worked previously with v2, I have already verified that handlebars versions are synced correctly between packages, I am using the newer packages with @jsreport/jsreport-core, and I've run out of ideas on how to move forward with this issue. Thanks for any help.

  • administrators

    @rsemler6789 the v3 parses the helpers differently, it parses the code in helpers and looks for top-level functions, and treat them as helpers. so it works differently

    it is not documented but if you want to do the same helpers registration (like v2) you can do something like this:

    __topLevelFunctions.testing = function () {
        return 'Hola'


    for your code i think you can change this last part to:

    // OLD: })(this)
    })(__topLevelFunctions) // NEW

    the recommended approach is still to do it with assets but if you don't want to do big changes to your app then use what i described above

  • Thanks so much for the quick response! The fix you recommended worked beautifully, and thanks for explaining the differences between v2 and v3 and how it handles the helpers.

Log in to reply

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.