Jsreport-core in electron app



  • Hello Jsreport team,

    I was following the jsreport inside electron app guide and it works in an standalone setting even today. However, since electron is already a big framework shipping chromium with every app, I thought JSreport-core would a better fit in this time. Since the officials guide is with jsreport, I think it can make the app bulky so want some advice on how to use jsreport-core in with electron.
    My strategy is to use chrome-pdf and then send the generated report from backend to frontend with electron-IPC.

    Further I am thinking of using electron forge as this now is the official package bundling toolkit from electron.

    My reporting app will be using below packages with jsreport-core:
    Engines: Handlebars & Jsrender both.
    Extensions: Assets, pdf-utils
    Recipes: Chrome-pdf and XLSX

    Few starting questions I have are as below:

    1. How different this will be from the official guide of using jsreport in electron?
    2. Will it work with electron forge or i need to be aware of sone configuration in order for it work?
    3. Can I use webpack templates provided by electron forge with making jsreport packages as external dependencies with webpack-node-externals? I know jsreport is not supposed to be used with bundling but still I would want try that as it will reduce my bundle size ( I have other dependencies too where this might be helpful however if too much efforts are required, I may simply drop the webpack template idea)

    Let me know your suggestions. Anyways I am starting this and will post the errors or struggles I face in this thread.



  • So I did try this and it worked fine in electron dev mode.
    Then I tried to pack the application with electron-builder first as per the guide.
    There I am encountering below error.

    Error: Cannot find module 'handlebars'
    Require stack:
    - D:\Electron Report Generator Builder\dist\win-unpacked\resources\app.asar\node_modules\@jsreport\jsreport-handlebars\lib\worker.js
    - D:\Electron Report Generator Builder\dist\win-unpacked\resources\app.asar\node_modules\@jsreport\jsreport-core\lib\worker\extensionsManager.js
    - D:\Electron Report Generator Builder\dist\win-unpacked\resources\app.asar\node_modules\@jsreport\jsreport-core\lib\worker\reporter.js
    - D:\Electron Report Generator Builder\dist\win-unpacked\resources\app.asar\node_modules\@jsreport\jsreport-core\lib\worker\workerHandler.js
    - D:\Electron Report Generator Builder\dist\win-unpacked\resources\app.asar\node_modules\@jsreport\advanced-workers\lib\workerHandler.js
    

    I am not able to understand why this error is throwing after I package the app and not in dev mode where I simply run the app using "electron . " command.

    This is how I am importing the jsreport engine

    const jsreport = jsreportCore({
      loadConfig: true,
      rootDirectory: process.cwd(),
    });
    jsreport.use(jsreportChromePdf());
    jsreport.use(jsreportHandlebars());
    jsreport.use(jsreportJsrender());
    jsreport.use(jsreportAssets());
    jsreport.use(jsreportPdfUtils());
    


  • Still on the same path of trying jsreport-core in electron app.
    However I just took a little detour to see if entire jsreport package can still work with electron.
    Quickly realized that the puppeteer executable path needs to be adjusted as latest puppeteer package now installs chrome binary in local users folder instead of relative node_modules folder. So manually copying the chrome binary from local users cache folder to electron distribution folder and referencing it to "process.env.extensions_chromePdf_launchOptions_executablePath" did the trick.

    However now chrome-pdf is timing out.

    Any suggestions??



  • The chrome that did come with jsreport 4.5.0 was timing out on windows, maybe you hit the same now
    https://forum.jsreport.net/topic/3234/read-this-if-you-experience-chrome-pdf-hanging-on-windows-in-jsreport-4-5-0

    I'm afraid you will need to check puppeteer/electron resources. It's a long time since we were testing with electron and currently prioritize other things.

    Or hopefully, someone from community will bring some light here.



  • Thanks for showing me the right direction.
    Actually I was using Jsreport 4.6.0 in first place and it was working in dev mode of electron (where the chromium downloaded by puppeteer was in User/.cache/puppeteer folder and version 4.6.0 already had a fix for this problem of permissions.)

    Once I packaged the app, chrome-pdf shown said issue as I had copied the chromium files inside my application package directory (which did not have the permissions). using icacls on this specific directory path did fix the issue however this seems difficult to setup once I package my app and distribute where I probably wont have the permissions to run icacls.

    It seems like the fix available in 4.6.0 is only applying to default path of puppeteer.
    Is there any way to apply the fix to the chromium path specified in launchOptions of jsreport.config.json



  • It seems like the fix available in 4.6.0 is only applying to default path of puppeteer.
    Is there any way to apply the fix to the chromium path specified in launchOptions of jsreport.config.json

    We had only updated the puppeteer in the 4.6.0. Nothing more. The perm problem is fixed in the new chrome installer as far as I've read the issues in chrome/puppeteer repo. You may have to run that icacls command on your own during the app startup.


Log in to reply
 

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