D
Deno

help

Getting exports from an evaluated module with get_module_namespace always results in null values

Bbaphomet_the_traveller9/26/2023
Trying to get module exports like the example here The module is loaded with load_main_module, I call mod_evaluate on the ID returned, then do the below: But the value returned is always undefined Js:
export function test() { return 2;}
export function test() { return 2;}
Rust:
let module_namespace = self.deno_runtime.get_module_namespace(module_id)?;
let mut scope = self.deno_runtime.handle_scope();
let module_namespace = v8::Local::<v8::Object>::new(&mut scope, module_namespace);

let key = v8::String::new(&mut scope, "test").unwrap();
let value = module_namespace.get(&mut scope, key.into()).unwrap();

println!("{}", value.is_undefined()); // true
let module_namespace = self.deno_runtime.get_module_namespace(module_id)?;
let mut scope = self.deno_runtime.handle_scope();
let module_namespace = v8::Local::<v8::Object>::new(&mut scope, module_namespace);

let key = v8::String::new(&mut scope, "test").unwrap();
let value = module_namespace.get(&mut scope, key.into()).unwrap();

println!("{}", value.is_undefined()); // true
GitHub
feat(core): Adds a new method get_module_namespace to access the na...
Allows users to access the namespace object of a module. Example - Extracting the default export binding of a JavaScript module using deno_core ... let module_namespace = runtime.get_module_namespa...
DAHDeno AI Helper9/26/2023
I'm sorry, but the documentation does not provide a clear answer to your question about why you're getting null values when trying to get exports from an evaluated module with get_module_namespace. It might be a good idea to check if the module is correctly loaded and evaluated before trying to access its exports. If the problem persists, you might want to ask for help in a Deno related community or forum, providing them with the complete code you're working with.
Bbaphomet_the_traveller9/26/2023
I know the module is loaded because I can pull values from global. It's just exports that don't work @mmastrac hate to bug you again, but
Mmmastrac9/26/2023
TBH I'm not familiar with that particular v8 API. It looks like it should work, but I'm not sure why it isn't. Sorry about that. Someone else may be able to help, however.
Bbaphomet_the_traveller9/26/2023
Alright!! I figured it out It was a small error in how I captured the module_id from the async move tokio was blocking on Can valid ModuleIds ever be 0? Since they are a usize Because if not, a check for that might be useful
Mmmastrac9/26/2023
NonZeroUsize in std::num - Rust
An integer that is known not to equal zero.
Bbaphomet_the_traveller9/26/2023
https://github.com/denoland/deno_core/blob/2af63b92b1e26871d44c6cf5db57464a761911f4/core/modules/map.rs#L381 Loader is created with next_load_id of 1 So it should never be 0 I think a NonZeroUsize makes more sense in that context, since usize has a default value which is invalid here Seems the 0 module_id is actually being used in a few spots to represent the lack of loaded modules, by reading it as self.handles.len()

Looking for more? Join the community!

Recommended Posts
Is there any way to define a signal inside a route component?Is there any way to define a signal inside a route component? I am trying to do it but an error raiDeno EmitHow come does `deno bundle` work a lot differently to Deno emit (https://deno.land/x/emit@0.28.0 )? `deno lsp` does not understand bare imports without prefixEven in minimal project, freshly created from a template, Deno marks imports as errors and doesn't uWhen I use crypto in this code, it returns 'Unknown cipher.'const secret ="**1111111111111111111**"; let encryptedText='test'; const decipher = crypto.cTroubleshooting deno.land downloadsI have docker containers, within a minikube cluster, that have trouble downloading https://deno.landRun remote Fresh application code locally.Is it possible to run a remotely hosted Fresh application? E.g. I'm attempting to do `deno run -A hmigrate from node to deno: p5js projectHi, I want to rewrite my p5js project built with nodejs in deno. Here is my code: https://github.coPeer dependencyCan I somehow mark a dependency as "peer"? So this dependency (which is known to shuffle typings bet'Spawn' multiple promises from the same moduleI'm trying to use Deno for scripted npcs in a game, the main issue that the npc has to await user acReturn results from execute_main_moduleI currently have this function to run some execute some js ``` pub async fn run(&self, path_to_Fresh Blog + Website Thingshttps://vuepress-theme-yuu.netlify.app/, what is the closest thing to that which can be run on FreshDetermine subcommandIf I run `deno test` from the command line, how can I determine that `test` is the subcommand being setting a cookie for import requestsis there a way to modify request headers or set cookies for the GET requests that deno makes when reHow to run tailwindcss cli with deno task?I would like to be able to run the tailwindcss cli tool to watch and build stylesheets as per their Deno DeployIs it possible to use only cronjobs on deno deploy?Deno cannot import mainfile by reading from package.jsondeno 1.36.0 (release, x86_64-unknown-linux-gnu) v8 11.6.189.12 typescript 5.1.6Deno LSP in a Web WorkerHas anyone come across the lsp running in a web worker? I have an online editor (Monaco) that peopleHow do you get a Deno Jupyter notebook to recognize Deno and other types in vscode?See attached screenshotModule not found when running deno runSomething weird has started happening. When I run `deno run src/main.ts` it seems as if Deno is tryesm_entry_point / extension macro; ReferenceErrorHow do I use esm_entry_point properly? I defined my extension as: ```rust extension!( ext_name,