Thanks @jan_blaha , really appreciate it.
Posts made by godhar
-
RE: Error: jsreport already initialized or just initializing. Make sure init is called only once
-
RE: Error: jsreport already initialized or just initializing. Make sure init is called only once
Hi! Thanks for getting back to me. Like this:
const jsreport = require('jsreport-core')(); let jsReportInitialized = false;
..........
function checkIfJsReportIsInit() { if( !jsReportInitialized ) { jsReportInitialized = true; return jsreport.init(); } return Promise.resolve(); }
............
return checkIfJsReportIsInit().then(() => { jsreport.render({ template: { content: htmlTemplate, engine: 'handlebars', recipe: 'chrome-pdf', chrome: { format: 'A4', printBackground: true, marginTop: '1in', marginRight: '0.5in', marginBottom: '0.25in', marginLeft: '0.5in' } }, data: modifiedReport }).then(resp => { return MailService.mailer(resp.content, 'ServiceReport.pdf', reportId, type); }); }).catch(err => { console.error(err); });
-
Error: jsreport already initialized or just initializing. Make sure init is called only once
Hi,
So I use jsreport to create a pdf from a template. So we prep the data and require in the html template then do the following:
jsreport.init().then(() => { return jsreport.render({ template: { content: htmlTemplate, engine: 'handlebars', recipe: 'chrome-pdf', chrome: { format: 'A4', printBackground: true, marginTop: '1in', marginRight: '0.5in', marginBottom: '0.25in', marginLeft: '0.5in' } }, data: modifiedReport }).then(resp => { return MailService.mailer(resp.content, 'ServiceReport.pdf', reportId, type); }); }).catch(err => { console.error(err); });
this is how I import it:
const jsreport = require('jsreport-core')();
these are the packages I have:
"jsreport-chrome-pdf": "^1.3.0", "jsreport-core": "^2.4.3", "jsreport-handlebars": "^2.0.1", "puppeteer": "^1.13.0",
I read you did not need to get jsreport to use those modules by calling use()
In development all is good. On the aws ec2 debian linux server it errors with
Error: jsreport already initialized or just initializing. Make sure init is called only once at Reporter.init (/home/ben/node/node_modules/jsreport-core/lib/reporter.js:99:29) at createJSReportPdf (/home/paul/node/pdfReport/composeServiceReports.js:49:12) at Object.sendReportEmail (/home/paul/node/pdfReport/composeServiceReports.js:16:10) at process._tickCallback (internal/process/next_tick.js:68:7)
This seems to happen after jsreport has been called once.
Any ideas of how to tackle this?
Much appreciated, thanks
Paul
-
Getting 'SyntaxError: Identifier 'err' has already been declared' in then block.
Hi,
Just trying out jsreport for it's ease off use. I got it going in a test project, now in the real thing, I keep getting the above syntax error and I can't figure out why.
Jsreport .render({ template: { content: reportString, engine: "handlebars", recipe: "chrome-pdf" } }) .then((resp) => { MailService.mailer( resp.content, "ServiceReport.pdf", report, type ).catch((err) => { console.error(err); }); }).catch((error) => { console.error(error); }); }
The error happens on MailService.... line. This is a service I call to send the result of the jsreport process. It is an asynchronous call, hence the catch.
I have tried putting a try catch and using the async/await style syntax as well to no effect. To be clear I have no global, or in scope var named 'err' in this file.
Any ideas? Googling has brought forth nothing.
Cheers!