Engine 'cheerio' not found. If this is a custom engine make sure it's properly installed from npm
Closed this issue · 2 comments
DiegoRugue commented
Hello, I'm getting an error when trying to use jsreport with cheerio engine, could you help me?
This is the error:
{
"logged": true,
"message": "Engine 'cheerio' not found. If this is a custom engine make sure it's properly installed from npm",
"stack": "Error: Engine 'cheerio' not found. If this is a custom engine make sure it's properly installed from npm at module.exports (c:\Momentum\grupokasil_reports\node_modules\jsreport-core\lib\util\createError.js:11:13) at Reporter.createError (c:\Momentum\grupokasil_reports\node_modules\jsreport-core\lib\reporter.js:328:12) at invokeRender (c:\Momentum\grupokasil_reports\node_modules\jsreport core\lib\render\render.js:38:20) at module.exports (c:\Momentum\grupokasil_reports\node_modules\jsreport-core\lib\render\render.js:149:11)",
"statusCode": 400,
"weak":true
}
My package.json:
{
"dependencies": {
"cheerio": "^1.0.0-rc.3",
"cheerio-page-eval": "^1.0.0",
"jsreport-core": "^2.6.2",
"jsreport-html-to-xlsx": "^2.4.1",
}
}
My implementation:
const jsreport = require('jsreport-core')({ tasks: { strategy: 'in-process' } });
jsreport.use(require('cheerio-page-eval'));
jsreport.use(require('jsreport-html-to-xlsx')());
async function createReport() {
await jsreport.init();
return await jsreport.render({
template: {
content: '<table><tr><td>Hello World!</td></tr></table>',
engine: 'cheerio',
recipe: 'html-to-xlsx'
}
});
}
bjrmatos commented
hi @DiegoRugue you probably got confused a bit. cheerio is an html-engine which is part of jsreport-html-to-xlsx strategies to evaluate and convert html to excel. it is not a template engine (like handlebars, pug, jsrender, etc) so the expected usage is more like this:
const jsreport = require('jsreport-core')({ tasks: { strategy: 'in-process' } });
jsreport.use(require('cheerio-page-eval'));
jsreport.use(require('jsreport-html-to-xlsx')());
async function createReport() {
try {
await jsreport.init();
const res = await jsreport.render({
template: {
content: '<table><tr><td>Hello World!</td></tr></table>',
engine: 'none',
htmlToXlsx: {
htmlEngine: 'cheerio'
},
recipe: 'html-to-xlsx'
}
});
console.log(`render completed: ${res.meta.reportName}.${res.meta.fileExtension}`)
} catch (e) {
console.error('Error while trying to render with jsreport:')
throw e
}
}
createReport()
also i'm sure you probably know but the last versions of the packages you are using looks like this:
"dependencies": {
"cheerio-page-eval": "1.0.0",
"jsreport-core": "2.7.2",
"jsreport-html-to-xlsx": "2.6.0"
}
just a mention, in case you hit another error because you are not using the correct last versions
DiegoRugue commented
Hi @bjrmatos, It worked! Thanks for help!