Import ESM module to sandbox
-
Hello,
Following the release of nodejs 22, we have migrated all our packages to ESM.
Our JS server is used on AWS lambda, and therefore launched manually. It contains dependencies on our own packages and scripts in addition to the JsReport architecture (data/scripts/template).
We are unable to migrate our JsReport server to nodejs 22 (deployed on lambda) because:
- migrating JsReport to ESM, migrating scripts to ESM, and importing into sandbox scripts causes errors stating that import cannot be called outside the module
- leaving JsReport in CommonJS means that we either cannot perform a basic import (import .... from ‘...’) since we are in CommonJs, or we get the error “” when using await import(‘’) or await require(‘’)
To be honest, I don't know how to call ESM scripts in the JsReport sandbox.
Thank you for your help.
Best Regards.!
-
hi! yes, it is not possible to use ESM inside the sandbox, it is mainly because of some limitations in the implementation of sandbox (vm module and vm scripts).
we are tracking the progress of it in this issue, there were some changes in node that will likely help with making ESM modules to work in sandbox, however we have not yet evaluated the full history.
this change will likely require a major version bump in jsreport so we are still in the process of planning the next major release, and when we are on that we will fully check if ESM is possible right now or not yet given the current nodejs features.
-
Re: Import ESM module to sandbox
Hi,
Thank you very much for your clear response.
AWS has announced that it will end support for NodeJs 18, and support for Nodejs 20 will end in June 2026.
Do you think the issue will be fixed by the time support for NodeJs 20 ends on ?
Thank you.