carboneio / carbone

Fast and simple report generator, from JSON to pdf, xslx, docx, odt...
https://carbone.io
Other
1.3k stars 189 forks source link

[Bug Report]: Carbone never resolves the report (with pkg) #107

Open pilotkid opened 3 years ago

pilotkid commented 3 years ago

Environment Carbone Version: Carbone 2.1.1 Node Version: 12.16.2 Browsers: N/A Desktop OS: Docker / Ubuntu 20 Other: pkg 4.4.9

Expected Behaviour Carbone finishes generating a report or throws an error

Actual Behaviour Carbone never completes generating the report or throws an error.

Steps to reproduce Steps to reproduce the bug:

  1. write a carbon application
  2. run it with node - it works fine
  3. package it using pkg pkg -t node12-win main.js
  4. run the output - it does not work.

Reproduction Link / Code example

carbone.render("/snapshot/build_report/test.docx", {a:1, b:2, c:3}, {convertTo: 'pdf'}, function (err, result) {
        print("rendered")        
        //IF THERE WAS AN ERROR RETURN IT
        if (err) {
            console.log(err);
            res.statusMessage = "Carbone had an error";
            res.set('Content-Type', 'application/json');
            res.status(400).send({ error: err.message });
            res.end()
            return;
        }

        //REPORT WAS SUCCESSFUL SEND BACK DATA
        res.set('Content-Type', returnType);
        res.send(result);
    });

Other comments I have a use case where I cannot have node installed on a client machine (libre office is already installed), so I am using a package called pkg that bundles nodejs with your source into an executable. However once bundled Carbone never is able to render and will just sit there for an infinite period of time (in my case 1 hour before I killed it)

steevepay commented 3 years ago

Hello @pilotkid, Have you tried to replace the absolute path by path.join('snapshot', 'build_report', 'test.docx')? Does it work with different templates?

pilotkid commented 3 years ago

Hello, I have attempted this solution to no avail.

No templates work as expected.

I have also tried moving to a different directory and that did not solve the issue. Hardcoding the path (E.G. C:\snapshot\build_report\test.docx), or using path.join does not work.

If I move the template to a different directory it also does not work.

It also does not work when I try to use relative directories.

I also would like to mention that if I use fs to read the file it works fine, I can read the full contents of the file using:

const data = fs.readFileSync(req.file.path, 'utf8')
console.log(data)

Note: I apologize for the delay I did not see that you replied until now.

steevepay commented 3 years ago

Hello @pilotkid, First, I passed the absolute path to Carbone with: const reportPath = path.join(__dirname, "template.docx");. I replicated the issue and it is not coming from the readFile. The issue is occurring when Carbone renders as a PDF, it is working when the export file type is a DOCX document. The issue seems to be the communication with Libre Office to convert to PDF. Carbone uses a python gateway converter.py to communicate with the Libre Office Uno API. The pkg project is not including the Python environment and it is limited to the node execution. The issue is not related directly to Carbone.