Closed
Description
Node's global
variable isn't defined when running code inside Node's vm
module.
Steps to reproduce
- Create a new project with
deno init
- Run
deno add npm:@marvinh/node-vm-test
- Run this script:
import "@marvinh/node-vm-test";
Contents of the npm package:
import vm from "node:vm";
const result = vm.runInThisContext(`global.foo = 1`);
console.log(result);
Error:
error: Uncaught (in promise) TypeError: Cannot set properties of undefined (setting 'foo')
at <anonymous>:1:12
at Script.runInThisContext (node:vm:9:12)
at Object.runInThisContext (node:vm:42:38)
at file:///Users/marvinh/dev/test/deno-vm-global/foo.mjs:3:15
Running the same script in Node:
$ node foo.mjs
1
Version: Deno 1.43.3