Script execution causing error during render ("Cannot read property 'forEach' of undefined")



  • Hey again,

    I'm unable to pinpoint the exact cause of this problem or replicate it at will, so I'm hoping I can get some insight here. It seems to be a result of a template's script execution failing in some way. But I'm not sure, to say the least. I saw a post was made on here with a similar query but it was unanswered.

    Here is the code from within the jsreport-core module itself that the error refers to:

      const engineRes = await reporter.executeScript({
        template: request.template,
        data: request.data,
        engine: request.template.pathToEngine,
        safeSandboxPath: reporter.options.templatingEngines.safeSandboxPath,
        appDirectory: reporter.options.appDirectory,
        rootDirectory: reporter.options.rootDirectory,
        parentModuleDirectory: reporter.options.parentModuleDirectory,
        templatingEngines: reporter.options.templatingEngines
      }, {
        execModulePath: pathToEngineScript
      }, request)
      //error happens on the following line
      engineRes.logs.forEach(function (m) {
        reporter.logger[m.level](m.message, {...request, timestamp: m.timestamp})
      })
    

    Again, any help is greatly appreciated :)



  • For the start, what jsreport (core) version you use? Thank you



  • Hey Jan! The version is 2.1.1. I'm guessing we should probably update to 2.2.0 ..... I'm not sure why we weren't on the latest version.



  • Not sure if it helps, maybe... I have a feeling we fixed this recently, but can't remember the details.
    In every case I see we have this issue reported 4 times but unfortunately no one was able to replicate it so far.

    If the update won't help. How often do you see this error?
    Could you add before this line some more logging?

    engineRes.logs.forEach(function (m) {
    

    Like

    reporter.logger.info(JSON.stringify(engineRes), request)
    


  • Ok, now we believe this was fixed in the latest jsreport-core@2.2.0.



  • Hey Jan,

    Thank you for your help.. I have updated to the latest version on our ec2 instance. But now I'm having a strange problem. I did npm uninstall before reinstalling to get to version 2.2.0, and I've verified that jsreport and jsreport-core are both showing the correct version. However, running "jsreport start" gives the following output:

    [ec2-user@ip-x-x-x-x jsreportapp]$ jsreport start configFile=jsreport.config.json
    2018-12-04T22:56:38.319Z - info: Initializing jsreport@2.2.0 in development mode using configuration file: none
    2018-12-04T22:56:38.322Z - info: Searching for available extensions in /home/ec2-user/jsreportapp/node_modules/jsreport/
    2018-12-04T22:56:38.377Z - info: Extensions location cache contains up to date information, skipping crawling in /home/ec2-user/jsreportapp/node_modules/jsreport/
    2018-12-04T22:56:38.378Z - info: Found 0 extensions
    2018-12-04T22:56:38.379Z - debug: Writing extension locations cache to /tmp/jsreport/core/locations.json
    2018-12-04T22:56:38.380Z - debug: Discovered 0 extensions
    2018-12-04T22:56:38.386Z - info: Setting process based strategy for rendering. Please visit http://jsreport.net/learn/configuration for information how to get more performance.
    2018-12-04T22:56:38.414Z - info: reporter initialized
    

    I have no idea why it appears to be starting without using the config file. The config file itself has correct contents. I've also tried without specifying the config file directly. Jsreport still does not appear as a process after saying "reporter initialized" and I can run "jsreport start" many times without getting any error messages, because the server is not actually started. I'm at a loss once more. Any chance you've got another solution for this? I'll keep working at it and update you if I can figure out what is happening.


  • administrators

    hi! i think this is caused by having duplicated jsreport-core in your deps, probably you have both jsreport and jsreport-core in your package.json which is not supported, inside your project you must have installed as direct dependency either jsreport or jsreport-core, not both. one way to see if you have duplicated jsreport-core in your dependencies tree is to run npm ls jsreport-core in your project. if you have duplicated jsreport-core the ouput will look something like this:

    jsreport2-test@0.0.1 /Volumes/DATA/workspace/jsreport2-test
    ā”œā”€ā”¬ jsreport@2.2.0
    ā”‚ ā””ā”€ā”€ jsreport-core@2.1.1
    ā””ā”€ā”€ jsreport-core@2.2.0
    

    it should be just one reference to jsreport-core, for your case you just need to update jsreport to 2.2.0, remove jsreport-core from your package.json. so it will be better for you to reinstall again without having jsreport-core listed in your package.json



  • You're totally right. I noticed right away after installing jsreport-core that it kept the previous version. I will give that a try, thank you so much!


  • administrators

    for the record, the fix that we were talking about is present in jsreport-core 2.1.1, which it is present in jsreport 2.2.0, so you just need to have jsreport on 2.2.0, no need to install or update anything related to core (it does not matter that core is not on 2.2.0, the important one is jsreport to be in 2.2.0)



  • Ah, that's very helpful to know. Normally I'm not the one who sets up these things for my team and I wasn't the one who set us up originally, but I really should be able to handle it.. I will work on my devops-type knowledge. Going through things like this is definitely helpful for my learning! As you can tell, I'm kind of a noob haha. I greatly appreciate the explanations :)


  • administrators

    you are welcome, to be honest, npm and its dependencies can be a little bit tricky to understand šŸ˜„


Log in to reply
 

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