You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
How do I require() modules from an isolate vm context (created via vm.createContext({})) while also capturing the globalThis accesses of require'd modules?
The builtin REPLServer has the same issue and the sample code below demoes it: the globalThis of a module I'm requireing is out of my reach.
I know that useGlobal: false creates a new vm context and performs a vm.runInContext() as opposed to a vm.runInThisContext() . If I do the same myself the result is the same.
I've traced this to compileFunctionForCJSLoader, which is an internal function and I don't see where it's being passed a context.
Node.js Version
v22.12.0
NPM Version
v11.0.0
Operating System
Linux
Subsystem
vm
Description
How do I
require()
modules from an isolate vm context (created viavm.createContext({})
) while also capturing theglobalThis
accesses of require'd modules?The builtin REPLServer has the same issue and the sample code below demoes it: the
globalThis
of a module I'mrequire
ing is out of my reach.I know that
useGlobal: false
creates a new vm context and performs avm.runInContext()
as opposed to avm.runInThisContext()
. If I do the same myself the result is the same.I've traced this to
compileFunctionForCJSLoader
, which is an internal function and I don't see where it's being passed a context.Minimal Reproduction
node my-repl.js
globalThis.two = 222
require('./b')
globalThis.one
one
is111
, and that the value of "two" is logged as222
. But both are undefinedOutput
Before You Submit
The text was updated successfully, but these errors were encountered: