laverdet / isolated-vm

Secure & isolated JS environments for nodejs
ISC License
2.19k stars 154 forks source link

TypeError: #<Promise> could not be cloned. #409

Closed chendetong1993 closed 1 year ago

chendetong1993 commented 1 year ago

Hello fellow developers,

I've tried the following code:

const isolate = new ivm.Isolate({ memoryLimit: 128 });
const context = isolate.createContextSync();
const ctxGlobal = context.global;

ctxGlobal.setSync('global', ctxGlobal.derefInto());
ctxGlobal.setSync('fetch', async function (...args) {
  // do somethings
});
const result = context.evalSync("(async ()=>{ await fetch(); })()");
return result;

However, I encountered an error "TypeError: # could not be cloned." I attempted to create an isolated environment using the ivm module and run asynchronous code within it, but it seems to be causing an issue.

Could someone please explain how this error is occurring? What steps should I take to resolve it?

Thank you very much for your assistance!

laverdet commented 1 year ago

Search docs for "transferable"