Unable to run pdf in docker node18.19



  • While running pdf template on docker container, I am getting below error. It is working outside docker.

    Report "basicCharts" render failed.

    Failed to launch the browser process! spawn /usr/bin/chromium-browser ENOENT

    TROUBLESHOOTING: https://pptr.dev/troubleshooting

    Error: Failed to launch the browser process! spawn /usr/bin/chromium-browser ENOENT

    TROUBLESHOOTING: https://pptr.dev/troubleshooting

    at ChildProcess.onClose (/usr/src/app/node_modules/@puppeteer/browsers/lib/cjs/launch.js:267:24)
    at ChildProcess.emit (node:events:517:28)
    at ChildProcess._handle.onexit (node:internal/child_process:290:12)
    at onErrorNT (node:internal/child_process:477:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)


  • #This is docker file

    FROM node:18.19.0

    WORKDIR /usr/src/app

    COPY . .

    RUN npm run setup

    EXPOSE 9012

    CMD [ "node", "server.js" ]



  • You typically can't just copy node_modules with puppeteer to the image.
    You should skip node_modules in the .dockerignore and instead run npm install in Dockerfile...
    However you will still hit problem with chrome dependencies, so I recommend:

    Either use our official images as base
    https://jsreport.net/learn/docker#customize-docker-image

    Or check how our images are created
    https://github.com/jsreport/jsreport/blob/master/packages/jsreport/docker/full/Dockerfile



  • I am using jsreport latest docker image and mounted the data and configuration files to container. I am not able to render pdf because of below error

    Could not find Chrome (ver. 121.0.6167.85). This can occur if either

    1. you did not perform an installation before running the script (e.g. npx puppeteer browsers install chrome) or
    2. your cache path is incorrectly configured (which is: /app/.puppeteer-cache).
      For (2), check out our guide on configuring puppeteer at https://pptr.dev/guides/configuration.
      Error: Could not find Chrome (ver. 121.0.6167.85). This can occur if either


  • You could be running jsreprot with a different user than the one that was used to install the puppeteer.
    Please share your updated dockerfile.



  • This is the dockerfile

    Use the jsreport/jsreport image version 4.2.0 as the base image
    FROM jsreport/jsreport:latest-full

    USER root

    COPY . .

    CMD [ "npm", "start" ]



  • #Use the jsreport/jsreport image version 4.2.0 as the base image
    FROM jsreport/jsreport:latest-full

    USER root

    RUN npm i handlebars-intl --save
    COPY --chown=jsreport:jsreport jsreport.config.json /app
    COPY --chown=jsreport:jsreport /data /app/data

    CMD [ "npm", "start" ]

    I used this docker file and it works fine. But I was using the code you fixed related to preprocessing in xlsx https://forum.jsreport.net/topic/3030/change-in-file-type-after-importing-xlsx-file/6 post install. As I am not able to modify loop.js in node_modules inside docker, is there any way to get those changes now?



  • Create a local folder, let's say patch, and put the changes you need to copy to the image there.
    For example

    patch/node_modules/@jsreport/jsreport-xlsx/lib/generation/preprocess/loop.js
    

    Then add a docker build step

    COPY --chown=jsreport:jsreport patch /app
    


  • Thanks a lot, worked for me.
    In my local environment, I'm able to successfully render a PDF with 12 charts distributed across two pages. However, when I attempt to replicate this within a Docker container, the output changes and I end up with each chart occupying a separate page. Is there any way to fix this?


Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.