Skip to content

Bug: Node vm doesn't have Node's global global #23852

Closed
@marvinhagemeister

Description

@marvinhagemeister

Node's global variable isn't defined when running code inside Node's vm module.

Steps to reproduce

  1. Create a new project with deno init
  2. Run deno add npm:@marvinh/node-vm-test
  3. 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

Metadata

Metadata

Labels

bugSomething isn't working correctlynode APIRelated to various "node:*" modules APIsnode compat

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions