ReferenceError: request is not defined



  • I am getting this error while I am trying to export excel file:
    Error when processing render request Error while executing user script. request is not defined. Error on line 3:5.

    1 | function beforeRender(req, res, done) {
    2 | var keys, columns;

    3 | if(request.data.data.removalListData && request.data.data.removalListData.length){
    | ^
    4 | keys = Object.keys(request.data.data.removalListData[0]);
    5 | columns = [];
    6 | keys.forEach(function (k) {

    ReferenceError: request is not defined
    at Object.beforeRender (evaluate-user-script.js:3:5)
    at Object.__runBefore (/media/piyush/E/js-report/node_modules/jsreport-scripts/lib/scriptEvalChild.js:107:26)
    at Object.apply (/media/piyush/E/js-report/node_modules/vm2/lib/contextify.js:288:34)
    at evaluate-user-script.js:25:1
    at ContextifyScript.Script.runInContext (vm.js:59:29)
    at VM.run (/media/piyush/E/js-report/node_modules/vm2/lib/main.js:212:72)
    at run (/media/piyush/E/js-report/node_modules/jsreport-core/lib/render/safeSandbox.js:171:19)
    at module.exports (/media/piyush/E/js-report/node_modules/jsreport-scripts/lib/scriptEvalChild.js:166:5)
    at process.<anonymous> (/media/piyush/E/js-report/node_modules/script-manager/lib/worker-processes.js:56:36)
    at emitTwo (events.js:126:13)

    It would be really appreciated if anybody will help me in this error? I am using js-report version: 2.3.0.
    Thanks in advance.


  • administrators

    hi! you have this at the top of your function

    function beforeRender(req, res, done) {
    

    you are naming the variable that the function receives res and you are trying to use it as request just change the usage to res or change the function param name to request



  • yes it worked, thanks @bjrmatos. In previous version we were using request only and at that time it was working fine. But I suppose it has changed now. Thanks again.


  • administrators

    yes, previous version request was defined globally in the script but we decided that it was bad to do it, so now you need to have the variable explicitly defined in the function



  • If you are using any script file and getting "Uncaught ReferenceError: x is not defined " which means ‘x’ is either a variable or a method which you are trying to use before declaring it using var keyword. This means that there is a non-existent variable referenced somewhere. This variable needs to be declared, or you need to make sure it is available in your current script or scope otherwise , it will endup throwing this ‘x’ is not defined error . This usually indicates that your library is not loaded and JavaScript does not recognize the ‘x’.

    To solve this error: Load your library at the beginning of all your scripts.

    There can be multiple other reasons for this issue:

    • Conflict with Other Libraries
    • Path to your library included is not correct
    • Llibrary file is corrupted
    • Working offline (when you use CDN)

Log in to reply
 

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