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

11 messages · Page 1 of 1 (latest)

lunar oxide
#

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;}

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
GitHub

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...

half sigilBOT
#

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.

lunar oxide
#

I know the module is loaded because I can pull values from global. It's just exports that don't work

lunar oxide
#

@red grail hate to bug you again, but

red grail
#

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.

lunar oxide
red grail
lunar oxide
#

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

lunar oxide
#

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()