Error generating HTML for xlsx
-
Hello guys, I have the following code:
const fs = require('fs'); const jsreport = require('jsreport-core')(); jsreport.use(require('jsreport-phantom-pdf')()); jsreport.use(require('jsreport-handlebars')()); jsreport.use(require('jsreport-html-to-xlsx')()); async function createReport(params) { try { if (jsreport && !jsreport._initialized) await jsreport.init(); let result = await jsreport.render({ template: { content: fs.readFileSync(`./src/resources/templates/${params.template}.html`, 'utf8'), engine: 'handlebars', recipe: 'html-to-xlsx', }, data: params.data }); return result.content; } catch (ex) { console.error(ex); throw ex; } }
and my model
<!DOCTYPE html> <html lang="pt-br"> <head> <meta charset="UTF-8"> <style> th { font-size: 20px; background: #1e88e5; } tr:nth-child(odd)>td { background: #6ab7ff; } td, th { text-align: center; font-size: 15px; padding: 10px; border: 3px solid black; } </style> </head> <body> <table style="line-height: 0;"> <tr> <th>Loja</th> <th>Tipo</th> <th>Consumidor</th> </tr> {{#each pedidos}} <tr style="height: 20px;"> <td>{{nomeLoja}}</td> <td>{{tipo}}</td> <td>{{nomeRazaoSocial}}</td> </tr> {{/each}} </table> </body> </html>
and I am getting this error:
Error: Error while executing html-to-xlsx recipe. Cannot read property 'name' of undefined at module.exports (D:\Workdir\ENGDIGITAL\Malta\artevinil-api\node_modules\jsreport-core\lib\util\createError.js:11:13) at Reporter.createError (D:\Workdir\ENGDIGITAL\Malta\artevinil-api\node_modules\jsreport-core\lib\reporter.js:332:12) at Object.execute (D:\Workdir\ENGDIGITAL\Malta\artevinil-api\node_modules\jsreport-html-to-xlsx\lib\recipe.js:159:20) at processTicksAndRejections (internal/process/task_queues.js:97:5) at async module.exports (D:\Workdir\ENGDIGITAL\Malta\artevinil-api\node_modules\jsreport-core\lib\render\render.js:150:5) at async createReport (D:\Workdir\ENGDIGITAL\Malta\artevinil-api\src\helpers\report.js:13:22) at async Object.gerarExcelPedidos (D:\Workdir\ENGDIGITAL\Malta\artevinil-api\src\core\pedido\service.js:355:16) at async gerarXlsx (D:\Workdir\ENGDIGITAL\Malta\artevinil-api\src\core\pedido\pedidoController.js:382:16) at async D:\Workdir\ENGDIGITAL\Malta\artevinil-api\src\api\middleware\catch.js:14:7 caused by: TypeError: Cannot read property 'name' of undefined at D:\Workdir\ENGDIGITAL\Malta\artevinil-api\node_modules\jsreport-html-to-xlsx\lib\scriptHtmlToXlsxProcessing.js:110:19 at Array.map (<anonymous>) at pageEval (D:\Workdir\ENGDIGITAL\Malta\artevinil-api\node_modules\jsreport-html-to-xlsx\lib\scriptHtmlToXlsxProcessing.js:109:19) at async convert (D:\Workdir\ENGDIGITAL\Malta\artevinil-api\node_modules\html-to-xlsx\lib\conversion.js:38:18) at async scriptHtmlToXlsxProcessing (D:\Workdir\ENGDIGITAL\Malta\artevinil-api\node_modules\jsreport-html-to-xlsx\lib\scriptHtmlToXlsxProcessing.js:66:20) { weak: true, logged: true
Can you help me?
-
hi!
maybe you can use these options:
{ template: { content: fs.readFileSync(`./src/resources/templates/${params.template}.html`, 'utf8'), engine: 'handlebars', recipe: 'html-to-xlsx', htmlToXlsx: { htmlEngine: "chrome" } } }
and make sure you have puppeteer installed
npm i puppeteer@2.0.0
-
@bjrmatos
It works on localhost but when going up to a docker container it didn't work. Error in the puppeteer question.Just for you to understand I have an endpoint that fetches the data in json and passes it to the generation of the report with the jsreport where my (angular) client only hits that endpoint. And all this service of mine is run in docker in hundreds.
-
docker is another story, there is some work you need to do for the puppeteer to work there, we already did such work in our official docker images, so if you are building your custom image you probably want to take a look at the source of the images and apply some of the steps in your image. you can also take a look at the steps mentioned in the puppeteer docs
-
Thanks, it works!