Skip to content
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

Deno panics import node:process from within a vm.Script #22441

Closed
tmcw opened this issue Feb 16, 2024 · 3 comments · Fixed by #23976
Closed

Deno panics import node:process from within a vm.Script #22441

tmcw opened this issue Feb 16, 2024 · 3 comments · Fixed by #23976
Assignees
Labels
bug Something isn't working correctly node API polyfill Related to various "node:*" modules APIs node compat

Comments

@tmcw
Copy link

tmcw commented Feb 16, 2024

Version: Deno 1.40.5

x.ts:

import vm from "node:vm";
const script = new vm.Script("import('node:process')");
script.runInNewContext();
❯ deno run x.ts

============================================================
Deno has panicked. This is a bug in Deno. Please report this
at https://github.com/denoland/deno/issues/new.
If you can reliably reproduce this panic, include the
reproduction steps and re-run with the RUST_BACKTRACE=1 env
var set and include the backtrace in your report.

Platform: macos aarch64
Version: 1.40.5
Args: ["deno", "run", "x.ts"]

thread 'main' panicked at /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/deno_core-0.262.0/runtime/jsrealm.rs:206:46:
called `Option::unwrap()` on a `None` value
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

This appears to be this file in deno_core: https://github.com/denoland/deno_core/blob/83906063c4c493a40958e4912c424c382c8afedb/core/runtime/jsrealm.rs#L206

It also seems to be present regardless of what you import from inside of the vm.Script, whether it's a node builtin, a local file, or an npm: prefixed import.

@ry ry added bug Something isn't working correctly node compat labels Feb 17, 2024
@bartlomieju bartlomieju added the node API polyfill Related to various "node:*" modules APIs label Mar 4, 2024
@rbetts rbetts changed the title Deno panicks import node:process from within a vm.Script Deno panics import node:process from within a vm.Script Apr 12, 2024
@ry
Copy link
Member

ry commented Apr 22, 2024

Still segfaults in 1.42.4

# deno run /tmp/foo.js

============================================================
Deno has panicked. This is a bug in Deno. Please report this
at https://github.com/denoland/deno/issues/new.
If you can reliably reproduce this panic, include the
reproduction steps and re-run with the RUST_BACKTRACE=1 env
var set and include the backtrace in your report.

Platform: macos aarch64
Version: 1.42.4
Args: ["deno", "run", "/tmp/foo.js"]

thread 'main' panicked at /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/deno_core-0.275.0/runtime/jsrealm.rs:208:46:
called `Option::unwrap()` on a `None` value
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

@bartlomieju
Copy link
Member

The gist of the problem is that node:vm creates a new V8 context, but it doesn't create related structures that would be set up for every single context - JsRealm, ModuleMap and ContextState. We will need to move some parts of node:vm module to be integrated directly with deno_core in order to solve this issue.

@csvn
Copy link

csvn commented Jun 4, 2024

I think this issue is the cause that deno run -A npm:@vercel/ncc fails with Uncaught TypeError: Cannot read properties of undefined (reading 'version'). The package uses new Script() from node:vm, and then it fails inside cli.js.cache.js due to process being undefined when calling process.version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly node API polyfill Related to various "node:*" modules APIs node compat
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants