Closed fuzing closed 2 years ago
This is not possible and I do currently not plan to add support for JS modules.
No worries - thank you!
On Sun, Aug 14, 2022 at 11:46 AM XmiliaH @.***> wrote:
This is not possible and I do currently not plan to add support for JS modules.
— Reply to this email directly, view it on GitHub https://github.com/patriksimek/vm2/issues/460#issuecomment-1214421594, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACY4CFORX2OO5DUBCGZSD4DVZEWG7ANCNFSM56QAQEHQ . You are receiving this because you authored the thread.Message ID: @.***>
I'm using the latest version of node (18.7 at time of writing) with VM2. I'd like to run some code as a string in a VM2 sandbox that uses ECMAScript import/export syntax instead of the commonjs require/exports.[something] = [the export]. I would strongly prefer not to have to transpile these imports/exports to commonjs.
I've made a number of attempts at trying to run a code string as an ECMAScript module but am not getting anywhere - i.e.
comes back with a SyntaxError: 'import' and 'export' may only appear with 'sourceType: module'.
I've tried setting my package.json "type" to "module", running VM2 from an ".mjs" file, along with combinations of this. I also have the:
set for my VM2 options.
Is this doable, or not possible with VM2? I'm presuming that using require to import an ".mjs" file once inside the sandbox will probably work, but I'd prefer to simply run the entire module as a string.
Thank you for any assistance.