D
Deno

help

Bootstrapping a minimal node-compatible runtime

Cchyyran10/16/2023
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?
DAHDeno AI Helper10/16/2023
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.
Bbaphomet_the_traveller10/17/2023
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
Cchyyran10/17/2023
Thanks, that seems to work
Bbaphomet_the_traveller10/17/2023
Happy to help

Looking for more? Join the community!

Recommended Posts
I want to adjust around tls using fetch APIWith nodejs, you could specify a cipher suite or version to be used with tls. Can't you do the same RUN deno task in DockerfileI have made a script to make DB migrations happen using "deno task migration", and I'd love for it tHelp Web.jsrq need help in web.js \ ```js window.paypal .Buttons({ style: { shape: "rect", laUnable to load env variables in localI'm starting again with deno since a long time with a small telegram bot using the `grammy` frameworWhy Bad resource ID occurs?I ran the following and got `error: BadResource: Bad resource ID` on seek. ```typescript import { toStorybook: some lightweight alternative for Deno?Do you know some lightweight alternative for [Storybook](https://storybook.js.org) to run on Deno?How can i change the location of Cache.open('somedb')We're deploying to docker containers which needs to write to an attached volume (specific path)How do I make Objects, Maps, etc. in rusty_v8 into easy-to-understand String?Hello. I wrote the following code in rusty_v8 ```rs let isolate = &mut v8::Isolate::new(Default:Usage of Deno.Command?Hey guys we use Deno.run to launch shell cmd and pipe the result to log. But Deno.run will be deprecWhen the destination server is down, WebSocketStream stops and the program crashes.I'm running the following code: ```const ws = new WebSocketStream("wss://localhost"); setInterval((Struggling with interactive FreshChartsHi there I'm trying to display charts in my fresh js project. i want to have them as islands accordiTurso with local db fileI wanted to try out Turso's syncURL feature and for that it creates a local db file to read from andImporting local NodeJS module from DenoIs it possible to import a javascript file that has `node` imports for standart modules like `http` how I can install antd in my deno project?how I can install antd in my deno project?