-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Bug: Node vm
doesn't have Node's global
global
#23852
Comments
The |
I don't think that's the problem. Most likely it's related to https://github.com/denoland/deno/blob/main/ext/node/global.rs not recognizing that we're running inside |
This code should work when in a Node context i.e |
@littledivy Fair point: I've published the snippet as an npm package and updated the reproduction steps accordingly. |
Also blocking the Docusaurus upgrade in denoland/docs#412 |
Took a look at this, and I can get it to work with this patch, but I'm not sure if this is the right fix. diff --git a/ext/node/global.rs b/ext/node/global.rs
index 0aaa6ed8b..a3722641d 100644
--- a/ext/node/global.rs
+++ b/ext/node/global.rs
@@ -267,7 +267,9 @@ fn current_mode(scope: &mut v8::HandleScope) -> Mode {
let Some(v8_string) =
v8::StackTrace::current_script_name_or_source_url(scope)
else {
- return Mode::Deno;
+ // TODO: Add a flag to scope for inline scripts created
+ // via node:vm
+ return Mode::Node;
};
let op_state = deno_core::JsRuntime::op_state_from(scope);
let op_state = op_state.borrow();
@@ -276,7 +278,7 @@ fn current_mode(scope: &mut v8::HandleScope) -> Mode {
};
let mut buffer = [MaybeUninit::uninit(); 2048];
let str = v8_string.to_rust_cow_lossy(scope, &mut buffer);
- if node_resolver.in_npm_package_with_cache(str) {
+ if str.starts_with("node:") || node_resolver.in_npm_package_with_cache(str) {
Mode::Node
} else {
Mode::Deno The first change isn't necessary for this particular reproduction case, but it is necessary to get |
Node's
global
variable isn't defined when running code inside Node'svm
module.Steps to reproduce
deno init
deno add npm:@marvinh/node-vm-test
Contents of the npm package:
Error:
Running the same script in Node:
Version: Deno 1.43.3
The text was updated successfully, but these errors were encountered: