Error occurred during reporter init: Error: Cannot find module 'handlebars'



  • When I work in my dev env everything is OK.
    But when I pack my project using "pkg", I got the following error.

    2022-07-28T12:00:52.239Z - error: Error occurred during reporter init: Error: Cannot find module 'handlebars'
    Require stack:

    • C:\snapshot\bmi\node_modules@jsreport\jsreport-handlebars\lib\worker.js
    • C:\snapshot\bmi\node_modules@jsreport\jsreport-core\lib\worker\extensionsManager.js
    • C:\snapshot\bmi\node_modules@jsreport\jsreport-core\lib\worker\reporter.js
    • C:\snapshot\bmi\node_modules@jsreport\jsreport-core\lib\worker\workerHandler.js
    • C:\snapshot\bmi\node_modules@jsreport\advanced-workers\lib\workerHandler.js
      at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
      at Function._resolveFilename (pkg/prelude/bootstrap.js:1955:46)
      at Function.resolve (node:internal/modules/cjs/helpers:108:19)
      at module.exports (C:\snapshot\bmi\node_modules@jsreport\jsreport-handlebars\lib\worker.js:4:121)
      at Object.init (C:\snapshot\bmi\node_modules@jsreport\jsreport-core\lib\worker\extensionsManager.js:12:74)
      at WorkerReporter.init (C:\snapshot\bmi\node_modules@jsreport\jsreport-core\lib\worker\reporter.js:52:34)
      at Object.init (C:\snapshot\bmi\node_modules@jsreport\jsreport-core\lib\worker\workerHandler.js:16:23)
      at init (C:\snapshot\bmi\node_modules@jsreport\advanced-workers\lib\workerHandler.js:89:23)
      at processAndResponse (C:\snapshot\bmi\node_modules@jsreport\advanced-workers\lib\workerHandler.js:43:23)
      at MessagePort.<anonymous> (C:\snapshot\bmi\node_modules@jsreport\advanced-workers\lib\workerHandler.js:98:12)
      2022-07-28T12:07:43.430Z - info: Initializing jsreport (version: 3.6.1, configuration file: none, nodejs: 16.16.0)


  • Packing is complicated and won't work out of the box for you.
    You can get some idea how it can work from our compile script
    https://github.com/jsreport/jsreport/blob/master/scripts/compile.js



  • Thanks for your response.
    I couldn't understand from the above link what should I do?
    Is a recommended way to package node project that include jsReport to exe?
    In previous projects (without jsReport) I used "pkg" and it worked well.

    Does jsReport has support?

    Thanks



  • My code:
    ...
    jsreport.use(require('@jsreport/jsreport-chrome-pdf')())
    jsreport.use(require('@jsreport/jsreport-handlebars')())
    jsreport.use(require('@jsreport/jsreport-assets')({
    searchOnDiskIfNotFoundInStore: true,
    allowedFiles: '/.',
    allowLocalFilesAccess: true
    }))
    ...

    const result = await jsreport.render({
    template: {
    content:this.contnet,
    engine: 'handlebars',
    recipe: 'chrome-pdf',
    helpers:this.helper
    },
    data: this.data
    })



  • Is a recommended way to package node project that include jsReport to exe?

    If it's not aboslutely necessary for your deployment, I wouldn't go that way.

    I couldn't understand from the above link what should I do?

    If you git clone jsreport repo, install it and then run yarn compile, it will compile the current jsreport app using pkg into exe. Its a complicated process which I won't go into details, but if you are in need, you can study the whole flow from the code.

    In previous projects (without jsReport) I used "pkg" and it worked well.

    jsreport includes also binary dependencies and dynamic imports so things aren't that simple and pkg doesn't work out of the box. It needs several tweaks to make it working.


Log in to reply
 

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