Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JsRuntime initialization fails when integrating deno_url extension #27413

Open
insuns opened this issue Dec 18, 2024 · 0 comments
Open

JsRuntime initialization fails when integrating deno_url extension #27413

insuns opened this issue Dec 18, 2024 · 0 comments

Comments

@insuns
Copy link

insuns commented Dec 18, 2024

I'm encountering an issue when integrating the deno_url extension into deno_core within a test project. Despite trying various approaches, I consistently receive the following error during JsRuntime initialization:

 Failed to initialize a JsRuntime: Following modules were not evaluated; make sure they are imported from other code: 
    - ext:deno_console/01_console.js 
   - ext:deno_url/00_url.js 
   - ext:deno_webidl/00_webidl.js 
   - ext:deno_url/01_urlpattern.js 

Cargo.toml:

[package]
name    = "deno_url_test"
version = "0.1.0"
edition = "2021"

[dependencies]
v8          = { version = "130.0.1", default-features = false }
deno_core   = { version = "0.326.0", default-features = false }
deno_url    = "0.183.0"
deno_webidl = "0.183.0"
deno_console = "0.183.0"
tokio       = { version = "1.35.1", features = ["full"] }
anyhow      = "1.0.75"

rust code:

use deno_core::error::AnyError;
use deno_core::{extension, op2, OpState};
use deno_core::{JsRuntime, RuntimeOptions};

#[op2]
#[string]
fn op_test() -> Result<String, AnyError> {
    Ok("Hello from Rust!".to_string())
}

extension! {
    TestExtension,
    ops = [op_test],
    state = |state: &mut OpState| {
        ()
    }
}

#[tokio::main]
async fn main() -> Result<(), AnyError> {
    let mut runtime = JsRuntime::new(RuntimeOptions {
        extensions: vec![
            TestExtension::init_ops(),
            deno_console::deno_console::init_ops_and_esm(),
            deno_webidl::deno_webidl::init_ops_and_esm(),
            deno_url::deno_url::init_ops_and_esm(),
        ],
        ..Default::default()
    });

    let code = r#"
import "ext:deno_webidl/00_webidl.js"; 
import "ext:deno_console/01_console.js"; 
import "ext:deno_url/00_url.js"; 
import "ext:deno_url/01_urlpattern.js";

Object.defineProperty(globalThis, "URL", {
  value: url.URL,
  enumerable: false,
  configurable: true,
  writable: true,
});

Object.defineProperty(globalThis, "URLPattern", {
  value: url.URLPattern,
  enumerable: false,
  configurable: true,
  writable: true,
});

Object.defineProperty(globalThis, "URLSearchParams", {
  value: url.URLSearchParams,
  enumerable: false,
  configurable: true,
  writable: true,
});

        const result = Deno.core.ops.op_test();
        console.log('Custom op result:', result);
    "#;

    runtime.execute_script("[test]", code).map_err(|e| {
        println!("Script execution error: {:?}", e);
        e
    })?;

    Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant