graaljs icon indicating copy to clipboard operation
graaljs copied to clipboard

Adding a classpath while no direct access to Node

Open chrisdhanaraj opened this issue 1 year ago • 2 comments

Hey there! I'm trying to leverage Graal to run Remix (React metaframework), but I run into a couple of issues - the most pressing one is that I can't add a --vm.cp anywhere to expose a Java class to my application

WebAssembly: Initially I get blocked by a WebAssembly error, which I can get around by enabling WebAssembly by leveraging the steps here.

then, when I want to add a Java class to my app, there doesn't seem to be a way to add in a --vm.cp to a command that looks like npm run remix dev.

When I try to spawn a node child-process that runs that and attach the --vm.cp script there, an error is flagged that I'm not in a polyglot environment, even though the argument has been set. Removing the vm.cp argument drops the polyglot env error.

What's the best way to tackle this?

chrisdhanaraj avatar Feb 19 '24 20:02 chrisdhanaraj

Adding some more context, if I run this command

"dev": "NODE_OPTIONS='--polyglot' NODE_POLYGLOT_OPTIONS='--js.webassembly --experimental-options' remix dev --manual",

This is where I can't seem to add a vm.cp argument anywhere. If I try to do a Java.addToClasspath(), I can't do it in native mode.

However, if I do add a --jvm flag in there (just trying out everything), I run into the same WebAssembly error (where it thinks polyglot is not enabled, despite the flag being present)

chrisdhanaraj avatar Feb 19 '24 21:02 chrisdhanaraj

As of 24.x, WebAssembly is enabled by default in Node now, so it should not be necessary to use these options anymore. I think in the graalnodejs-community-jvm standalone, both --vm.cp and Java.addToClasspath() should work.

woess avatar Apr 24 '24 16:04 woess