caoccao / Javet

Javet is Java + V8 (JAVa + V + EighT). It is an awesome way of embedding Node.js and V8 in Java.
https://www.caoccao.com/Javet/
Apache License 2.0
698 stars 68 forks source link

Module cache error #376

Open aiselp opened 1 month ago

aiselp commented 1 month ago
V8Host.getNodeInstance().createV8Runtime<NodeRuntime>().use { runtime ->
            runtime.getNodeModule(NodeModuleModule::class.java).setRequireRootDirectory(File("/"))
            runtime.v8ModuleResolver = JavetBuiltInModuleResolver()
            runtime.getExecutor("""
                import events from "node:events"
                import stream from "node:stream"

                globalThis.a = events === stream
            """.trimIndent()).setModule(true).executeVoid()
            runtime.await()
            println("a: ${runtime.globalObject.getBoolean("a")}")
        }

This will print true, which means that the same module is returned. If you replace import stream from "node:stream" with const stream = require("node:stream"), it will print false normally. image

caoccao commented 1 month ago

Thank you for reporting this issue. It's quite weird. I just fixed it in the dev branch. Please wait for the next release.

aiselp commented 1 month ago

Very strange, just put import events below and it will print fasle