Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

require/load - Error loading JavaScript Module with ES4X in maven project #597

Open
iskane opened this issue Nov 24, 2022 · 3 comments
Open

Comments

@iskane
Copy link

iskane commented Nov 24, 2022

We have a polyglot application with Vertx 3 and vertx-lang-js and we are migrating to Vertx 4 and ES4X.
In lot of javaScripts we load other scripts that are in the classpath using require/load. for example:
var myvar = require('com/xxxx/yyyy/common/scripts/lodash.js')

Using Java 11, GraalVM and the ES4X dependency in our maven project, we have the following error when we load a javaScript module in a jar in the class path:

"ModuleError: Module "com/xxxx/yyyy/common/scripts/lodash.js"
was not found\r\n\tat Require.resolve(..\..\..\..\..\maven-local-repository\io\reactiverse\es4x\0.19.1\es4x-0.19.1.jar!\io\reactiverse\es4x\jvm-npm.js:122:3628-3706)

it’s possible with ES4X to resolve the class path and load a JavaScript file/module in a jar?

Thank you

@pmlopes
Copy link
Contributor

pmlopes commented Nov 24, 2022

This should definitely be possible as currently the require function use vert.x file system to resolve resources. Because of this, we should see jar resources as if they were local file system files.

Can you share a dummy jar/zip with the right location of the module you're trying to load and the require statement so I can debug if there's a specific issue with the setup?

I also see from your slashes you're probably on Windows, while I think this isn't an issue anymore it could be that with all the windows fixes in the last iterations we may have missed some edge cases...

@iskane
Copy link
Author

iskane commented Nov 24, 2022

Here is an example created from Deven Phillips tutorials.
https://github.com/iskane/es4x-example/blob/main/intro-to-vertx-master.zip

Configuration : graalvm-ce-java17-22.3.0 / es4x

"mvn clean compile vertx:run " and i have the following error:

Starting vert.x application...
[INFO] 10e265dd-ad24-48ba-a93d-12361380b92b-redeploy
[INFO] Failed in deploying verticle caused by ModuleError: Module "META-INF/resources/webjars/lodash/4.17.15/lodash.js" was not found
[INFO] at Require.resolve(.....m2\repository\io\reactiverse\es4x\0.19.1\es4x-0.19.1.jar!\io\reactiverse\es4x\jvm-npm.js:122:3628-3706)
[INFO] at Require(.....m2\repository\io\reactiverse\es4x\0.19.1\es4x-0.19.1.jar!\io\reactiverse\es4x\jvm-npm.js:89:2669-2695)
[INFO] at this.require(.....m2\repository\io\reactiverse\es4x\0.19.1\es4x-0.19.1.jar!\io\reactiverse\es4x\jvm-npm.js:46:1459-1475)
[INFO] at :anonymous(/C:/Users/iskan/IdeaProjects/intro-to-vertx-master/Hello.js:1:75-136)
[INFO] at _load(.....m2\repository\io\reactiverse\es4x\0.19.1\es4x-0.19.1.jar!\io\reactiverse\es4x\jvm-npm.js:73:2195-2276)
[INFO] at runMain(.....m2\repository\io\reactiverse\es4x\0.19.1\es4x-0.19.1.jar!\io\reactiverse\es4x\jvm-npm.js:85:2567-2611)
[INFO] at org.graalvm.sdk/org.graalvm.polyglot.Value.invokeMember(Value.java:973)

Thank you.

@iskane
Copy link
Author

iskane commented Nov 29, 2022

Hello,

I managed to make it work in this example project with the javaScript files in the same jar we used in our production project.
However, it does not work in our real project.

The only difference is that in the example we have one module and in the real project we have several modules and we import the module with the JS into another module.

It would be great to have documentation of how to migrate from Vertx 3 + vertx-lang-js to vertx 4 + es4X.
When I look at the documentation that exists, I have the impression that ES4X is designed to create a separate npm project and in our case, we have JS verticals deployed from a java maven project.

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants