oracle / graaljs

A ECMAScript 2024 compliant JavaScript implementation built on GraalVM. With polyglot language interoperability support. Running Node.js applications!
Universal Permissive License v1.0
1.78k stars 189 forks source link

Adding a classpath while no direct access to Node #799

Open chrisdhanaraj opened 7 months ago

chrisdhanaraj commented 7 months ago

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 commented 7 months ago

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)

woess commented 5 months ago

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.