Javet icon indicating copy to clipboard operation
Javet copied to clipboard

Module imports not working

Open akashKarmakar02 opened this issue 1 year ago • 5 comments

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

akashKarmakar02 avatar Jul 09 '24 13:07 akashKarmakar02

Please review the doc.

caoccao avatar Jul 09 '24 14:07 caoccao

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.

akashKarmakar02 avatar Jul 09 '24 14:07 akashKarmakar02

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

caoccao avatar Jul 09 '24 14:07 caoccao

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

akashKarmakar02 avatar Jul 09 '24 14:07 akashKarmakar02

READ THE DOC.

caoccao avatar Jul 09 '24 15:07 caoccao