Ejs render fail with "cannot read properties of undefined (reading 'Promise')"



  • I'm upgrading from a quite old version of jsreport (V2.X) where all the templates to be rendered are ejs-based.
    In this context, jsreport is used as custom service which only provide the render REST endpoint (accessed with jsreport-client). I'm not using studio, the full template to be rendered is passed to such rest endpoint.

    While testing the latest version 4.5.0 i'm getting a ejs error:

    jsreport warn: Error when processing render request 1
      jsreport (because) error when evaluating engine ejs for template anonymous
      jsreport (because) cannot read properties of undefined (reading 'Promise')
      jsreport 
      jsreport (sandbox.js line 13:18)
      jsreport TypeError: Cannot read properties of undefined (reading 'Promise')
      jsreport   at Object.<anonymous> (C:\progetti\jsreport-server\node_modules\ejs\lib\ejs.js:109:55)
      jsreport   at Module._compile (node:internal/modules/cjs/loader:1256:14)
      jsreport   at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
      jsreport   at Module.load (node:internal/modules/cjs/loader:1119:32)
      jsreport   at Module._load (node:internal/modules/cjs/loader:960:12)
      jsreport   at Module.require (node:internal/modules/cjs/loader:1143:19)
      jsreport   at require (node:internal/modules/cjs/helpers:110:18)
      jsreport   at requireMap (C:\progetti\jsreport-server\node_modules\@jsreport\jsreport-core\lib\worker\sandbox\runInSandbox.js:88:18)
      jsreport   at sandboxRequire (C:\progetti\jsreport-server\node_modules\@jsreport\jsreport-core\lib\worker\sandbox\requireSandbox.js:47:25)
      jsreport   at require (C:\progetti\jsreport-server\node_modules\@jsreport\jsreport-core\lib\worker\sandbox\createSandbox.js:89:30)
      jsreport   at Object.compile (C:\progetti\jsreport-server\node_modules\@jsreport\jsreport-ejs\lib\ejsEngine.js:6:19)
      jsreport   at executionFn (C:\progetti\jsreport-server\node_modules\@jsreport\jsreport-core\lib\worker\render\executeEngine.js:239:44)
      jsreport   at eval (sandbox.js:13:18)
      jsreport   at async run (C:\progetti\jsreport-server\node_modules\@jsreport\jsreport-core\lib\worker\sandbox\createSandbox.js:132:18)
      jsreport   at async WorkerReporter.runInSandbox [as _runInSandbox] (C:\progetti\jsreport-server\node_modules\@jsreport\jsreport-core\lib\worker\sandbox\runInSandbox.js:214:14)
      jsreport   at async executeEngine (C:\progetti\jsreport-server\node_modules\@jsreport\jsreport-core\lib\worker\render\executeEngine.js:342:16)
      jsreport wrapped by:
      jsreport Error: Error when evaluating engine ejs for template anonymous
      jsreport (because) cannot read properties of undefined (reading 'Promise')
      jsreport   at module.exports (C:\progetti\jsreport-server\node_modules\@jsreport\jsreport-core\lib\shared\createError.js:10:13)
      jsreport   at WorkerReporter.createError (C:\progetti\jsreport-server\node_modules\@jsreport\jsreport-core\lib\shared\reporter.js:53:12)
      jsreport   at executeEngine (C:\progetti\jsreport-server\node_modules\@jsreport\jsreport-core\lib\worker\render\executeEngine.js:365:35)
      jsreport   at async engine.engine (C:\progetti\jsreport-server\node_modules\@jsreport\jsreport-core\lib\worker\render\executeEngine.js:146:14)
      jsreport   at async invokeRender (C:\progetti\jsreport-server\node_modules\@jsreport\jsreport-core\lib\worker\render\render.js:61:23)
      jsreport   at async WorkerReporter._render (C:\progetti\jsreport-server\node_modules\@jsreport\jsreport-core\lib\worker\render\render.js:148:7)
      jsreport   at async C:\progetti\jsreport-server\node_modules\@jsreport\jsreport-core\lib\worker\reporter.js:232:24
      jsreport   at async processAndResponse (C:\progetti\jsreport-server\node_modules\@jsreport\advanced-workers\lib\workerHandler.js:41:17)
    

    Checking the logs looks like it's mostly a ejs-related error, but can't figure out if the newe version requires to change some request parameter.

    Also tried to check out the online playground, but i can't reproduce it.

    Using different engines is not anoption, unless i find the willing to change 100+ reports :)

    Using node 18.16.1.

    Are there some suggestions?


  • administrators

    hi! @ivanvaccari Unfortunately ejs is a library that can not work in a sandbox (which is enabled by default)

    you can disable the sandbox (and therefore allowing your jsreport server to render your templates) by using the trustUserCode: true in your configuration



  • Thanks, it works now.


Log in to reply
 

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