[Solved] Meteor with Carbone.io giving error in console

I’m running an application in Meteor, and install carbone js (a reporting engine), and in trying to setup their example, I get an error in the console that stops it from loading the page, or letting me use any navigation. I need some help figuring our what this error means.

First I do import fs from 'fs' and import carbone from 'carbone'; in place of their “require” option.

Then in the

Template.xxxxx.onRendered(function() {
    carbone.render('../../node_modules/carbone/examples/simple.odt', data, function(err, result){
        if (err) {
          return console.log(err);
        } else {
            // write the result
            fs.writeFileSync('result.odt', result);

When I do this, in the console I get the error:

caught TypeError: Cannot read properties of undefined (reading 'split')
    at module (modules.js?hash=1bff4c9fffe5133aed935ba8427f3ed368933960:66536:41)
    at fileEvaluate (modules-runtime-hot.js?hash=325e29e1f9abcee55f3cef85ec8a56670bbc6194:388:7)
    at Module.require (modules-runtime-hot.js?hash=325e29e1f9abcee55f3cef85ec8a56670bbc6194:270:27)
    at require (modules-runtime-hot.js?hash=325e29e1f9abcee55f3cef85ec8a56670bbc6194:310:21)
    at module (modules.js?hash=1bff4c9fffe5133aed935ba8427f3ed368933960:66119:14)
    at fileEvaluate (modules-runtime-hot.js?hash=325e29e1f9abcee55f3cef85ec8a56670bbc6194:388:7)
    at Module.require (modules-runtime-hot.js?hash=325e29e1f9abcee55f3cef85ec8a56670bbc6194:270:27)
    at require (modules-runtime-hot.js?hash=325e29e1f9abcee55f3cef85ec8a56670bbc6194:310:21)
    at module (modules.js?hash=1bff4c9fffe5133aed935ba8427f3ed368933960:65490:12)
    at fileEvaluate (modules-runtime-hot.js?hash=325e29e1f9abcee55f3cef85ec8a56670bbc6194:388:7)

I’m not sure how to go about fixing this issue. I know it’s the Carbone because when I comment it out the system works fine again.

One thought I had, is maybe it has to be run server side, but I don’t think that’s it.

Any help is greatly appreciated.

Carbone’s documentation states that it only runs server side (node). You are running it client side, not in node. So there’s your issue. A solution would be to use a Meteor method to send the relevant data from the client to the server and then run carbone there.

1 Like

Ok. It is a server-side thing. I don’t know why, but seemed like that wasn’t right, but I guess it is. Thank you.

I have one more question. I’m trying to do just what you’ve said, but the file that is needed for the render ‘simple.odt’ just doesn’t seem to be able to be found on the server (I’m guessing since Meteor does a little build).

I created a folder under my ‘server’ folder called ‘Files’, and put a copy of the ‘simple.odt’ file in it. But when I run the function, it doesn’t find the path or file, as it’s not being included in the build from what I can tell.

How / where can i get the application to recognize the ‘simple.odt’ file from the server location?

Ok, to answer myself, I was able to find the node_modules path where the original ‘simple.odt’ is at on the server and use that, but not idea to include files in that location. I’ll keep working on this.

If that file is something static that you want to include when building the app, then you might want to check out the special /private directory: Assets | Meteor API Docs

If the file is something more dynamic and you don’t want to rebuild the app every time the file changes, then you will need to look into another approach. For example fetching the file from some external resource before you run the carbone code.

Additionally, you might want to consider moving the file generation function away from the Meteor server altogether. File generation can often cause spikes in CPU or memory utilization as it uses up all available resources for a short while. Since the Meteor server is serving users, it can lead to bad UX. Due to this file generation is a prime candidate for serverless functions such as AWS Lamda. No need to think about scaling at all and no adverse effects on the main Meteor app. To give it a shot, read this: Setting Up Serverless Framework With AWS