Error rendering report after deployment
-
Hi, I am deploying an application that renders a report from javascript and I get the following error. I have tried to place the data directory in different places and I get the same error in all of them.
DOMException [DataCloneError]: [object Array] could not be cloned. at new DOMException (node:internal/per_context/domexception:53:5) at Worker.postMessage (node:internal/worker:352:5) at /usr/src/app/node_modules/@jsreport/advanced-workers/lib/threadWorker.js:52:16 at new Promise (<anonymous>) at postAndWait (/usr/src/app/node_modules/@jsreport/advanced-workers/lib/threadWorker.js:36:12) at Object.execute (/usr/src/app/node_modules/@jsreport/advanced-workers/lib/threadWorker.js:145:14) at Object.execute (/usr/src/app/node_modules/@jsreport/advanced-workers/lib/pool.js:65:35) at MainReporter.executeWorkerAction (/usr/src/app/node_modules/@jsreport/jsreport-core/lib/main/reporter.js:574:35) at MainReporter.render (/usr/src/app/node_modules/@jsreport/jsreport-core/lib/main/reporter.js:470:41) at async AssessmentsService.getReport (/usr/src/app/apps/api/main.js:326056:24)
This is the code I use to render the report.
const options = { logger: { file: { transport: "file", level: "debug", filename: '/logs/log' }, error: { transport: "file", level: "error", filename: '/logs/error.log' }, }, store: { provider: 'fs' }, extensions: { "fs-store": { dataDirectory: '/data', externalModificationsSync: false, enabled: true } } }; const jsreport = require('@jsreport/jsreport-core')(options); jsreport.use(require('@jsreport/jsreport-assets')()); jsreport.use(require('@jsreport/jsreport-chrome-pdf')()); jsreport.use(require('@jsreport/jsreport-data')()); jsreport.use(require('@jsreport/jsreport-fs-store')()); jsreport.use(require('@jsreport/jsreport-jsrender')()); jsreport.use(require('@jsreport/jsreport-pdf-utils')({ syncModifications: false })); jsreport.use(require('@jsreport/jsreport-localization')()); jsreport.render({ template: { name: 'reportName' }, data: {...}, options: { localization: { language: 'en' }, } });
-
You actually need to call
jsreport.init
so this doesn't seem to be completed.
Please share a github repository fully replicating the issue so we can take a look. Thank you.
-
Sorry, I forgot to copy that line in my previous post but I was actually calling jsreport.init. The code works fine in the development environment, but I get that error when I run it from the dist directory and the whole application crashes. I have checked the paths to the data directory in the jsreport startup logs and it is correct. However, I get the same error if I set up a data directory that doesn't exist.
const options = { logger: { file: { transport: "file", level: "debug", filename: '/logs/log' }, error: { transport: "file", level: "error", filename: '/logs/error.log' }, }, store: { provider: 'fs' }, extensions: { "fs-store": { dataDirectory: '/data', externalModificationsSync: false, enabled: true } } }; const jsreport = require('@jsreport/jsreport-core')(options); jsreport.use(require('@jsreport/jsreport-assets')()); jsreport.use(require('@jsreport/jsreport-chrome-pdf')()); jsreport.use(require('@jsreport/jsreport-data')()); jsreport.use(require('@jsreport/jsreport-fs-store')()); jsreport.use(require('@jsreport/jsreport-jsrender')()); jsreport.use(require('@jsreport/jsreport-pdf-utils')({ syncModifications: false })); jsreport.use(require('@jsreport/jsreport-localization')()); await jsreport.init(); await jsreport.render({ template: { name: 'reportName' }, data: {...}, options: { localization: { language: 'en' }, } });
Sorry, but I don't have the code on github and I can't upload the whole project right now. Maybe I can try to make a repository with part of the code.
-
The same code works for me.
The problem is that it seems you send some kind of unserializable object to the
jsreport.render
.
What you actually send in thedata
? There should be just plain objects.Sorry, but I don't have the code on github and I can't upload the whole project right now. Maybe I can try to make a repository with part of the code.
Yes I was asking just for some minimal reproducing code. Not the whole app.
-
It seems to have something to do with an array I'm passing in the data. I changed it to pass the data stringified and it seems to work fine now.
jsreport.render({ template: { name: 'reportName' }, data: JSON.stringify({...}), options: { localization: { language: 'en' }, } });
Thank you!