Custom NPM dependencies being removed, causing 'Unable to find module' error



  • I’ve encountered a strange issue recently.
    I'm using jsreport version 3.13.0, and my custom Dockerfile looks like this:

    
    FROM jsreport/jsreport:3.13.0
    
    RUN npm i client-oauth2@4.3.3 --save --save-exact
    
    COPY --chown=jsreport:jsreport jsreport.config.json /app
    

    In one of my scripts, I import the client-oauth2 library and use it according to the documentation (https://jsreport.net/learn/templating-engines). Everything works smoothly at first, but once the number of requests increases, I start getting the following error:

    0_1727781912212_error_message.png

    It seems that, at some point, dependencies from the tmp directory are being removed.
    Does anyone know why this might be happening? Could there be something wrong with my configuration?



  • I've tried to replicate the issue with the following setup.

    jsreport.config.json

    {
        "trustUserCode": true,
        "tempDirectory": "/app/tmp"
    }
    

    Dockerfile

    FROM jsreport/jsreport:3.13.0
    
    RUN npm i client-oauth2@4.3.3 --save --save-exact
    
    COPY --chown=jsreport:jsreport jsreport.config.json /app
    

    A template with html recipe and "Hello world" content with attached script

    async function beforeRender (req, res) {
        const jsreport = require("jsreport-proxy")    
        console.log(await jsreport.npm.require("client-oauth2@4.3.3"))
    }
    

    Then I run a load test with the following code, which results in 0 errors.

    const client = require('@jsreport/nodejs-client')('http://localhost:5488')
    
    function runOne () {
      return client.render({
        template: {
          name: 'test'
        }
      })
    }
    
    async function runMany () {
      for (let i = 0; i < 1000; i++) {
        await Promise.all([runOne(), runOne(), runOne(), runOne(), runOne()])
        console.log(i * 5)
      }
    }
    
    runMany().then(() => console.log('done')).catch(console.error)
    

    Could you try to replicate the error in a simple way like this?

    Note that when the dependency is installed in the image, you don't need to use the jsreport.npm.require. You can call simply the require('client-oauth2')


Log in to reply
 

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