-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
vm
: constants
is undefined
#52716
Comments
It is available if you use default import: import vm from "node:vm"; But it does seem like a bug that it isn't exposed as a named export (maybe because it's experimental?). |
Can't reproduce:
|
Using your same code: $ node test.mjs
[Object: null prototype] {
USE_MAIN_CONTEXT_DEFAULT_LOADER: Symbol(vm_dynamic_import_main_context_default)
}
# used `require` here
$ node test.cjs
[Object: null prototype] {
USE_MAIN_CONTEXT_DEFAULT_LOADER: Symbol(vm_dynamic_import_main_context_default)
} Both worked. I am now a tadbit confused, when I build my project and compile to bytecode, I am using the vm later on to interpret it. This is some of the bytecode loader code: const fs = require("fs");
const path = require("path");
const {Script,constants} = require("node:vm");
const v8 = require("v8");
const Module = require("module");
v8.setFlagsFromString("--no-lazy");
v8.setFlagsFromString("--no-flush-bytecode");
const FLAG_HASH_OFFSET = 12;
const SOURCE_HASH_OFFSET = 8;
let dummyBytecode;
console.log(constants); // logs 'undefined'
function setFlagHashHeader(bytecodeBuffer) {
if (!dummyBytecode) {
const script = new Script("", {
produceCachedData: true,
// trying to actually use it here
});
dummyBytecode = script.createCachedData();
}
dummyBytecode.slice(FLAG_HASH_OFFSET, FLAG_HASH_OFFSET + 4).copy(bytecodeBuffer, FLAG_HASH_OFFSET);
};
// .... |
Maybe somehow you are not using the right version of Node.js that has vm.constants to load it? |
Running process.versions.node pretty much answered it. I am using version 20 at runtime, but my version is 22. Not sure how to force an upgrade, I tried nvmrc, npmrc, engine strict, and engines config but they didn't do it. Might be a case of my project dependencies bundled with node 20? |
Hi, it seems the issue was resolved, but if anyone disagrees, please re open this issue |
Version
22.0.0
Platform
Microsoft Windows NT 10.0.22631.0 x64
Subsystem
No response
What steps will reproduce the bug?
Import
constants
fromnode:vm
. Log it, it returnsundefined
How often does it reproduce? Is there a required condition?
No response
What is the expected behavior? Why is that the expected behavior?
constants
is meant to return an objectWhat do you see instead?
undefined
Additional information
Was following along this issue: #51154
I wanted to be able to use
import
in myScript
instance, and the constants are supposed to allow me use the default loader without flags, but the constants object is returning undefined. I am usingThe text was updated successfully, but these errors were encountered: