Executing the script: Unable to find module



  • So I've updated to 2.1 jsreport (using the packaged server jsreport-win.exe), but I'm running into problem with the jsreport unable to find the module. I've tried to install the module globally and also right in the same folder as the jsreport-win is, but with no luck. Any ideas are welcome.

    Error while executing user script. Unable to find module request
    Searched paths:
    request
    D:\Installers\jsreport-win\request
    D:\Installers\jsreport-win\request
    D:\Installers\jsreport-win\request
    .
    7 | var http = require('http');
    8 | var https = require('https');
    9 | var request = require('request');
    | ^
    10 |
    11 | function getAGSData(token, req, done) {
    12 | console.log('--------------------------- AGOL Data Retreival ------------------------');

    I believe I have pretty standard jsreport.config.json

    {
      "extensions": {
        "authentication": {
          "cookieSession": {
            "secret": "<your strong secret here>"
          },
          "admin": {
            "username": "admin",
            "password": "password"
          },
          "enabled": false
        },
        "scripts": {
          "timeout": 40000,
          "allowedModules": "*"
        }
      },
      "httpPort": 5488,
      "store": {
        "provider": "fs"
      },
      "blobStorage": {
        "provider": "fs"
      },
      "logger": {
        "console": {
          "transport": "console",
          "level": "debug"
        },
        "file": {
          "transport": "file",
          "level": "info",
          "filename": "logs/reporter.log"
        },
        "error": {
          "transport": "file",
          "level": "error",
          "filename": "logs/error.log"
        }
      },
      "allowLocalFilesAccess": true,
      "templatingEngines": {
        "timeout": 10000
      },
      "chrome": {
        "timeout": 40000
      }
    }
    

  • administrators

    hi! are you sure that you installed request module correctly? where is its exact path in your D:\Installers\jsreport-win directory? can you show the files that you have inside the D:\Installers\jsreport-win?



  • Thanks for the quick reply. The folder structure looks like this
    d:\Installers\jsreport-win
    |---- [folder] data
    |---- [folder] logs
    |---- [folder] node_modules
    |---- jsreport.config.json
    |---- jsreport-win.exe
    |---- license.txt
    |---- package-lock.json

    I'm sure something pretty obvious but I've tried global modules and eveerything. Interestingly, I had the same setup for 1.9.2 and that one worked ok. Perhaps the config file (which has changed) is missing something. Thanks again, great tool.

    Interestingly, if I run the script from within the same folder
    node test.js

    it runs correctly. Also, the following lines

    var path = require.resolve('querystring')
    console.log(path);
    var path2 = require.resolve('request');
    console.log(path2);
    

    return

    querystring
    D:\Installers\jsreport-win\node_modules\request\index.js

    But if I run it from the jsreport studio it's reporting the errror:

    Error while executing user script. require.resolve is not a function. Error on line 10:20.

    I can report that 1.10 works ok, but 2.1 is giving me the grief above


  • administrators

    ok, i can reproduce this error as you mentioned, i will try to find the reason why this is not working. thanks


  • administrators

    Interestingly, if I run the script from within the same folder
    node test.js

    it runs correctly. Also, the following lines

    var path = require.resolve('querystring')
    console.log(path);
    var path2 = require.resolve('request');
    console.log(path2);
    return

    querystring
    D:\Installers\jsreport-win\node_modules\request\index.js
    But if I run it from the jsreport studio it's reporting the errror:
    Error while executing user script. require.resolve is not a function. Error on line 10:20.
    I can report that 1.10 works ok, but 2.1 is giving me the grief above

    i think require.resolve is not supported from scripts so this will never work when that code executes as part of jsreport.



  • So again, you have acknowledged that it's a bug in your current release that one cannot access the external modules. Is that correct? I need to get back to the team and explain what's happening. Cheers


  • administrators

    So again, you have acknowledged that it's a bug in your current release that one cannot access the external modules. Is that correct?

    yes, it is a bug with the executable version of jsreport v2.1.x.

    we are still working on finding the bug, in the mean time you can use nodejs/npm based installation if you are in hurry, and then when the fix is done in executable switch back to it if you prefer it



  • Thanks! will try to run it from cmd line then but I need it as a service running under a specific service account for the proxy authorization (worst setup ever), we are using NSSM to do that, not sure how could I run it as that specific user, this is a deep dive into nodejs for me. With regards, Michal


Log in to reply
 

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