Skip to content

How to load a module not from the file system? #4262

Closed Answered by Aworldc
Aworldc asked this question in Q&A
Discussion options

You must be logged in to vote

Don't know why, but that ain't working. Got it working by writing a custom ModuleLoader that takes in a function that maps paths to strings of js:

use {
    boa_engine::{
        Context, JsError, JsResult, JsString, Module, Source,
        module::{ModuleLoader, resolve_module_specifier},
    },
    std::{env::current_dir, error::Error},
};

type MyResult<T> = Result<T, Box<dyn Error>>;

struct ModuleResolver(fn(written_path: String, resolved_path: String) -> MyResult<String>);

impl ModuleLoader for ModuleResolver {
    fn load_imported_module(
        &self,
        referrer: boa_engine::module::Referrer,
        specifier: JsString,
        finish_load: Box<dyn FnOnce(JsResult<Module>, &

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@Aworldc
Comment options

@nekevss
Comment options

@Aworldc
Comment options

Answer selected by Aworldc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants