chyyran
chyyran9mo ago

Bootstrapping a minimal node-compatible runtime

I'm trying to bootstrap a minimal node-compatible runtime, so I've basically been copying and pasting MainWorker and removing things I don't need like napi or kv
let permissions = PermissionsContainer::allow_all();

let mut extensions = vec![
// Web APIs
deno_webidl::deno_webidl::init_ops_and_esm(),
deno_console::deno_console::init_ops_and_esm(),
deno_url::deno_url::init_ops_and_esm(),
deno_web::deno_web::init_ops_and_esm::<PermissionsContainer>(
options.blob_store.clone(),
options.bootstrap.location.clone(),
),
deno_fetch::deno_fetch::init_ops_and_esm::<PermissionsContainer>(
deno_fetch::Options {
user_agent: options.bootstrap.user_agent.clone(),
root_cert_store_provider: options.root_cert_store_provider.clone(),
unsafely_ignore_certificate_errors: options
.unsafely_ignore_certificate_errors
.clone(),
file_fetch_handler: Rc::new(deno_fetch::FsFetchHandler),
..Default::default()
},
),
deno_websocket::deno_websocket::init_ops_and_esm::<PermissionsContainer>(
options.bootstrap.user_agent.clone(),
options.root_cert_store_provider.clone(),
options.unsafely_ignore_certificate_errors.clone(),
),
deno_crypto::deno_crypto::init_ops_and_esm(options.seed),

deno_net::deno_net::init_ops_and_esm::<PermissionsContainer>(
options.root_cert_store_provider.clone(),
options.unsafely_ignore_certificate_errors.clone(),
),
deno_tls::deno_tls::init_ops_and_esm(),
deno_http::deno_http::init_ops_and_esm::<DefaultHttpPropertyExtractor>(),
deno_io::deno_io::init_ops_and_esm(Some(options.stdio)),
deno_fs::deno_fs::init_ops_and_esm::<PermissionsContainer>(
options.fs.clone(),
),
deno_node::deno_node::init_ops_and_esm::<PermissionsContainer>(
options.npm_resolver,
options.fs,
),
deno_permissions_worker::init_ops_and_esm(
permissions,
false,
),
];
let permissions = PermissionsContainer::allow_all();

let mut extensions = vec![
// Web APIs
deno_webidl::deno_webidl::init_ops_and_esm(),
deno_console::deno_console::init_ops_and_esm(),
deno_url::deno_url::init_ops_and_esm(),
deno_web::deno_web::init_ops_and_esm::<PermissionsContainer>(
options.blob_store.clone(),
options.bootstrap.location.clone(),
),
deno_fetch::deno_fetch::init_ops_and_esm::<PermissionsContainer>(
deno_fetch::Options {
user_agent: options.bootstrap.user_agent.clone(),
root_cert_store_provider: options.root_cert_store_provider.clone(),
unsafely_ignore_certificate_errors: options
.unsafely_ignore_certificate_errors
.clone(),
file_fetch_handler: Rc::new(deno_fetch::FsFetchHandler),
..Default::default()
},
),
deno_websocket::deno_websocket::init_ops_and_esm::<PermissionsContainer>(
options.bootstrap.user_agent.clone(),
options.root_cert_store_provider.clone(),
options.unsafely_ignore_certificate_errors.clone(),
),
deno_crypto::deno_crypto::init_ops_and_esm(options.seed),

deno_net::deno_net::init_ops_and_esm::<PermissionsContainer>(
options.root_cert_store_provider.clone(),
options.unsafely_ignore_certificate_errors.clone(),
),
deno_tls::deno_tls::init_ops_and_esm(),
deno_http::deno_http::init_ops_and_esm::<DefaultHttpPropertyExtractor>(),
deno_io::deno_io::init_ops_and_esm(Some(options.stdio)),
deno_fs::deno_fs::init_ops_and_esm::<PermissionsContainer>(
options.fs.clone(),
),
deno_node::deno_node::init_ops_and_esm::<PermissionsContainer>(
options.npm_resolver,
options.fs,
),
deno_permissions_worker::init_ops_and_esm(
permissions,
false,
),
];
However when it crashes on JsRuntime::new
thread 'main' panicked at 'assertion failed: `(left == right)`
left: `Evaluated`,
right: `Instantiated`: Module already evaluated. Perhaps you've re-provided a module or extension that was already included in the snapshot? ext:deno_node/02_init.js (43)', /Users/chyyran/.cargo/registry/src/index.crates.io-6f17d22bba15001f/deno_core-0.222.0/runtime/jsrealm.rs:546:5
thread 'main' panicked at 'assertion failed: `(left == right)`
left: `Evaluated`,
right: `Instantiated`: Module already evaluated. Perhaps you've re-provided a module or extension that was already included in the snapshot? ext:deno_node/02_init.js (43)', /Users/chyyran/.cargo/registry/src/index.crates.io-6f17d22bba15001f/deno_core-0.222.0/runtime/jsrealm.rs:546:5
Is there anything I seem to be missing that could cause this error?
4 Replies
Deno AI Helper
Deno AI Helper9mo ago
Based on the documentation, the error message you're seeing suggests that a module or extension has been evaluated more than once. This could happen if you're including a module or extension in your runtime that's already included in a snapshot you're using. The JsRuntime::new function is used to create a new JavaScript runtime with the specified options. In your case, it seems like one of the extensions you're adding to your runtime is causing the issue. The extensions you're adding with init_ops_and_esm are initializing both the ops and the ECMAScript modules for various Deno features. If one of these extensions is already included in a snapshot you're using, it could cause the module to be evaluated twice, leading to the error you're seeing. Without more information about your setup, it's hard to say exactly which extension is causing the issue. However, you could try commenting out each extension one by one to see which one is causing the error. Once you've identified the problematic extension, you can investigate further to see why it's being evaluated twice. Remember that this advice is not explicitly stated in the documentation, but it's a general debugging approach that could help you identify the issue.
baphomet_the_traveller
You using a snapshot to init the runtime? If so just use init_ops not init_ops_and_esm The esm is already in the snapshot
chyyran
chyyran9mo ago
Thanks, that seems to work
baphomet_the_traveller
Happy to help