rustyscript icon indicating copy to clipboard operation
rustyscript copied to clipboard

[node_experimental] TypeError: testEnabled is not a function

Open silverpill opened this issue 10 months ago • 3 comments

Describe the bug

Server.listen fails with an error: TypeError: testEnabled is not a function

To Reproduce

use rustyscript::{Error, Module, Runtime};

fn main() -> Result<(), Error> {
    let module = Module::new(
        "test.js",
        r#"
        import * as net from "node:net"
        const server = net.createServer()
        server.listen(8124, () => {
            console.log("server bound")
        })
        "#
    );
    let () = Runtime::execute_module(
        &module, vec![],
        Default::default(),
        &(),
    )?;
    Ok(())
}

Expected behavior

This JavaScript snippet works in Deno.

silverpill avatar Feb 28 '25 19:02 silverpill

Seems I missed a function somewhere in my boostrapping! Seems to be part of the polyfills, I'm surprised its not there

rscarson avatar Mar 05 '25 15:03 rscarson

Fixed in master, will leave this open this the next version publishes.

rscarson avatar Mar 14 '25 14:03 rscarson

Thank you! TypeError doesn't appear when running rustyscript from master, but the code from the example still doesn't work as it does in Deno.

The "server bound" message is never printed, and the server doesn't appear to be listening. Edited example (added await to prevent program from terminating immediately):

use rustyscript::{Error, Module, Runtime};

fn main() -> Result<(), Error> {
    let module = Module::new(
        "test.js",
        r#"
        import * as net from "node:net"
        const server = net.createServer()
        server.listen(8124, () => {
            console.log("server bound")
        })

        export default async function test() {
            await new Promise((resolve, reject) => {
                server.on("listening", resolve)
                server.on("error", reject)
            })
        }
        "#
    );
    let mut runtime = Runtime::new(Default::default())?;
    let handle = runtime.load_module(&module)?;
    let () = runtime.call_entrypoint(
        &handle,
        &(),
    )?;
    Ok(())
}

silverpill avatar Mar 16 '25 18:03 silverpill

Fixed in release 0.12.0

rscarson avatar Aug 16 '25 03:08 rscarson