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
674 stars 64 forks source link

Module imports not working #367

Open akashKarmakar02 opened 1 month ago

akashKarmakar02 commented 1 month ago

In Javet i want to use module import but it is saying no module found but when i use require it pick the correct package from node_modules

caoccao commented 1 month ago

Please review the doc.

akashKarmakar02 commented 1 month ago

var node = NodeJsRunTimeProvider.getRuntime();
node.getNodeModule(NodeModuleModule.class).setRequireRootDirectory(new File(JavetOSUtils.WORKING_DIRECTORY));
node.setV8ModuleResolver(new JavetBuiltInModuleResolver());
System.out.println(JavetOSUtils.WORKING_DIRECTORY);
node.getExecutor(output.getCode()).setModule(true).executeVoid();```

What am i doing wrong.
caoccao commented 1 month ago

require() doesn't involve the module resolver. Please read the doc.

akashKarmakar02 commented 1 month ago

i am using import React from "react" it is failing saying module not found but. const React = require("react") works

caoccao commented 1 month ago

READ THE DOC.