reactiverse / es4x Goto Github PK
View Code? Open in Web Editor NEW๐ fast JavaScript 4 Eclipse Vert.x
Home Page: https://reactiverse.io/es4x/
License: Apache License 2.0
๐ fast JavaScript 4 Eclipse Vert.x
Home Page: https://reactiverse.io/es4x/
License: Apache License 2.0
the current bindings are pushed by this project, this is not a real requirement as anyone could push their own. The process should be documented and properly explained.
This would allow usage of es4x without npm, and npm script could just delegate to it when needed.
The goal is to allow referring to other jars as if they were npm modules.
Hi, I'm trying es4x with an existing graphql application and our old boot file was:
export NODE_PATH=build/
node build/server.js
It's not a huge deal, but doing vertx-scripts launcher run build/server.js
from our root project directory can't find the compiled files in build/
so I have to cd
into build
and then run vertx-scripts launcher run server.js
.
Not a blocker but just thought I'd mention it. Maybe NODE_PATH
is too much "pretending to be like node" and would be confusing, but some sort of equivalent would be nice. (I also recently tried graal's node
replacement and it supported NODE_PATH
just fine, although that makes sense as they are purposefully trying to be a node
drop-in.)
Following the initial clean start, it doesn't work.
mkdir my-app
cd my-app
npm init -y
npm add vertx-scripts --save-dev
npm add @vertx/unit --save-dev
npm add @vertx/core --save-prod
npm add @vertx/web --save-prod
I created the provided index.js / index.test.js
(you forgot to warn about doing a "vertx-scripts init" (for the pom file to be produced / overwritten)
I myself did a global npm install of vertx-scripts, because it would otherwise not recognize it as a command (Windows!)
The error produced was:
Caused by: jdk.nashorn.internal.runtime.ParserException: <eval>#88:17<eval>:3:0 Expected an operand but found import
import { Router } from '@vertx/web';
How to solve this?
All working well now, except for debugger. I tried to get the debugger to work with IntelliJ on port 9797 but IntelliJ would only show decompiled byte code. Have you managed to get the debugger to work, and was that on vscode or something?
Even though Nashorn and Graaljs implement JS standard typed arrays, many server side modules depend on node specific Buffer
type. For this reason there should be a polyfill for it on ES4X
.
Currently graaljs is used if the JVM is a GraalVM JVM, since it is now possible to run graaljs on stock JDK, the detection mechanism must allow this use case.
This will reduce the current amount of errors trying to generate typedoc's
Hi, I'm getting this run when trying to run a graal script in es4x:
TypeError: Access to host class io.vertx.ext.web.handler.BasicAuthHandler is not allowed or does not exist.
at <js> :anonymous(/home/stephen/company/app/node_modules/@vertx/web/index.js:3:137-190)
at <js> _load(src/main/resources/io/reactiverse/es4x/jvm-npm.js:126:3641-3722)
at <js> Require(src/main/resources/io/reactiverse/es4x/jvm-npm.js:148:4250-4274)
at <js> this.require(src/main/resources/io/reactiverse/es4x/jvm-npm.js:99:2911-2927)
at <js> :anonymous(vertx.js:9:219-239)
at <js> _load(src/main/resources/io/reactiverse/es4x/jvm-npm.js:126:3641-3722)
at <js> Require(src/main/resources/io/reactiverse/es4x/jvm-npm.js:148:4250-4274)
at org.graalvm.polyglot.Value.execute(Value.java:312)
at io.reactiverse.es4x.impl.graal.GraalLoader.require(GraalLoader.java:129)
at io.reactiverse.es4x.impl.graal.GraalLoader.main(GraalLoader.java:139)
at io.reactiverse.es4x.impl.graal.GraalLoader.main(GraalLoader.java:31)
at io.reactiverse.es4x.VerticleFactory$1.start(VerticleFactory.java:103)
at io.vertx.core.impl.DeploymentManager.lambda$doDeploy$8(DeploymentManager.java:491)
at io.vertx.core.impl.ContextImpl.lambda$wrapTask$2(ContextImpl.java:339)
at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:404)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:463)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:886)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
I'm pretty sure I've ran the incantation correctly, e.g. per other issue I've cd
'd into the build
directory, ran ../node_modules/.bin/vertx-scripts init
and package
to create the mvn/pom.xml files (that now existing within the build/
directory itself).
I also grabbed a quick snapshot of the classpath:
stephen 22379 0.0 0.1 6830392 26180 pts/2 Sl+ 08:09 0:00 java -cp /home/stephen/.m2/repository/io/vertx/vertx-core/3.5.4/vertx-core-3.5.4.jar:/home/stephen/.m2/repository/io/netty/netty-transport/4.1.19.Final/netty-transport-4.1.19.Final.jar:/home/stephen/.m2/repository/io/netty/netty-codec-http/4.1.19.Final/netty-codec-http-4.1.19.Final.jar:/home/stephen/.m2/repository/io/netty/netty-buffer/4.1.19.Final/netty-buffer-4.1.19.Final.jar:/home/stephen/.m2/repository/io/netty/netty-codec-dns/4.1.19.Final/netty-codec-dns-4.1.19.Final.jar:/home/stephen/.m2/repository/io/netty/netty-codec/4.1.19.Final/netty-codec-4.1.19.Final.jar:/home/stephen/.m2/repository/io/netty/netty-codec-socks/4.1.19.Final/netty-codec-socks-4.1.19.Final.jar:/home/stephen/.m2/repository/com/fasterxml/jackson/core/jackson-core/2.9.6/jackson-core-2.9.6.jar:/home/stephen/.m2/repository/io/netty/netty-codec-http2/4.1.19.Final/netty-codec-http2-4.1.19.Final.jar:/home/stephen/.m2/repository/com/fasterxml/jackson/core/jackson-annotations/2.9.0/jackson-annotations-2.9.0.jar:/home/stephen/.m2/repository/io/netty/netty-common/4.1.19.Final/netty-common-4.1.19.Final.jar:/home/stephen/.m2/repository/io/netty/netty-handler/4.1.19.Final/netty-handler-4.1.19.Final.jar:/home/stephen/.m2/repository/io/netty/netty-resolver-dns/4.1.19.Final/netty-resolver-dns-4.1.19.Final.jar:/home/stephen/.m2/repository/io/reactiverse/es4x/0.5.4/es4x-0.5.4.jar:/home/stephen/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.9.6/jackson-databind-2.9.6.jar:/home/stephen/.m2/repository/io/netty/netty-resolver/4.1.19.Final/netty-resolver-4.1.19.Final.jar:/home/stephen/.m2/repository/io/netty/netty-handler-proxy/4.1.19.Final/netty-handler-proxy-4.1.19.Final.jar:/home/stephen/company/app/build/target/classes io.vertx.core.Launcher run vertx.js
Hm. I see vertx-core
on there but not vertx-web
...I have both in my package.json
:
$ cat package.json | grep vertx
"@vertx/core": "^3.5.3",
"@vertx/web": "^3.5.3",
"vertx-scripts": "^1.1.4"
And have done yarn install
/etc. Do you have any ideas?
This can be done with Java9 and Dynalink
The definition files are generated from java interfaces, where it is allowed to declare constants. In order to generate valid TypeScript code, the constants should be moved to a module definition with the same name as the interface, and the interface should be clean of constants.
Alternative approach would be looking at mixins and handle the Java interfaces as TypeScript abstract classes.
Both nashorn and graal allow filtering which classes can be accessed from the script context. This is a good security / isolation feature that could get added really quickly.
In some modules, variable names use reserved keywords making the definitions invalid.
They should be filtered.
Graal supports generators out of the box, having a package a la co
would make it easier to write synchronous code.
Currently the repl
/shell
is a extra main class that replicated the vertx launcher in some parts, to simplify the code and reduce duplication the shell should be integrated with the current verticle factory which would allow testing and less duplication.
es4x scripts and package bin uses /bin/sh instead of /bin/bash which breaks for lack of pushd.
Since ubuntu 17, the default bash in Ubuntu is dash
, which lacks pushd and does not support all the sintax supported by bash.
I found this errors when running npm install
or npm start
on an example project using es4x-pm.
node_modules/.bin/es4x: pushd: not found /node_modules/.bin/es4x: 6: node_modules/.bin/es4x: Bad substitution
I just replaced the first line in es4x binary to #!/bin/bash
and in the project generated binary also and the errors were fixed.
I'm trying this out and have a question about integrating some of my Java code with the ES code.
From what I understand so far, you need to create a .pom.xml handlebars template and use dependencies to include the custom jar file. Is that right?
Also, how do you then use the Java classes with the ES code?
I'd really love to see an easy solution for using my existing Java code with a JavaScript based router. Thanks for your hard work!
Hi,
i search a solution to customize the Dockerfile, for example add cluster parameter in the entrypoint, for now i change directly into the Dockerfile but i think we can do better like .pom.xml ?
Maybe we can do it but i don't find how.
I just packaged a jar with JVMCI=1 npm run package
, but when i run the command to start the jar:
/home/abner2/.sdkman/candidates/java/11.0.1-open/bin/java \
--module-path=target/compiler \
-XX:+UnlockExperimentalVMOptions \
-XX:+EnableJVMCI \
--upgrade-module-path=target/compiler/compiler.jar \
-jar target/es4x-java11-1.0.0-bin-jvmci.jar
I'm facing this exception:
org.graalvm.polyglot.PolyglotException: java.lang.IllegalStateException: No language for id regex found. Supported languages are: [js]
at <js> :anonymous(Unknown)
at <js> :program(console.js:16-183:608-5011)
at org.graalvm.sdk/org.graalvm.polyglot.Context.eval(Context.java:331)
at io.reactiverse.es4x.impl.graal.GraalRuntime.<init>(GraalRuntime.java:197)
at io.reactiverse.es4x.impl.graal.GraalRuntime.<init>(GraalRuntime.java:71)
at io.reactiverse.es4x.Runtime.getCurrent(Runtime.java:58)
at io.reactiverse.es4x.VerticleFactory.createVerticle(VerticleFactory.java:43)
at io.vertx.core.impl.DeploymentManager.createVerticles(DeploymentManager.java:237)
at io.vertx.core.impl.DeploymentManager.lambda$doDeployVerticle$2(DeploymentManager.java:210)
at io.vertx.core.impl.FutureImpl.setHandler(FutureImpl.java:79)
at io.vertx.core.impl.DeploymentManager.doDeployVerticle(DeploymentManager.java:177)
at io.vertx.core.impl.DeploymentManager.doDeployVerticle(DeploymentManager.java:149)
at io.vertx.core.impl.DeploymentManager.deployVerticle(DeploymentManager.java:137)
at io.vertx.core.impl.VertxImpl.deployVerticle(VertxImpl.java:665)
at io.vertx.core.impl.launcher.commands.VertxIsolatedDeployer.deploy(VertxIsolatedDeployer.java:42)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at io.vertx.core.impl.launcher.commands.ClasspathHandler.deploy(ClasspathHandler.java:159)
at io.vertx.core.impl.launcher.commands.RunCommand.deploy(RunCommand.java:397)
at io.vertx.core.impl.launcher.commands.RunCommand.run(RunCommand.java:270)
at io.vertx.core.impl.launcher.VertxCommandLauncher.execute(VertxCommandLauncher.java:226)
at io.vertx.core.impl.launcher.VertxCommandLauncher.dispatch(VertxCommandLauncher.java:380)
at io.vertx.core.impl.launcher.VertxCommandLauncher.dispatch(VertxCommandLauncher.java:324)
at io.vertx.core.Launcher.main(Launcher.java:45)
Original Internal Error:
java.lang.IllegalStateException: No language for id regex found. Supported languages are: [js]
at org.graalvm.truffle/com.oracle.truffle.polyglot.PolyglotEngineImpl.findLanguage(PolyglotEngineImpl.java:443)
at org.graalvm.truffle/com.oracle.truffle.polyglot.PolyglotImpl$EngineImpl.parseForLanguage(PolyglotImpl.java:473)
at org.graalvm.truffle/com.oracle.truffle.api.TruffleLanguage$Env.parse(TruffleLanguage.java:1787)
at com.oracle.truffle.js.runtime.JSContext.getRegexEngine(JSContext.java:934)
at com.oracle.truffle.js.runtime.RegexCompilerInterface.compile(RegexCompilerInterface.java:75)
at com.oracle.truffle.js.runtime.RegexCompilerInterface.compile(RegexCompilerInterface.java:66)
at com.oracle.truffle.js.nodes.access.RegExpLiteralNode.execute(RegExpLiteralNode.java:92)
at com.oracle.truffle.js.nodes.access.JSWriteCurrentFrameSlotNodeGen.execute_generic3(JSWriteCurrentFrameSlotNodeGen.java:149)
at com.oracle.truffle.js.nodes.access.JSWriteCurrentFrameSlotNodeGen.execute(JSWriteCurrentFrameSlotNodeGen.java:84)
at com.oracle.truffle.js.nodes.access.JSWriteCurrentFrameSlotNodeGen.executeVoid(JSWriteCurrentFrameSlotNodeGen.java:281)
at com.oracle.truffle.js.nodes.control.AbstractBlockNode.executeVoid(AbstractBlockNode.java:74)
at com.oracle.truffle.js.nodes.control.BlockNode.execute(BlockNode.java:62)
at com.oracle.truffle.js.nodes.function.FunctionBodyNode.execute(FunctionBodyNode.java:66)
at com.oracle.truffle.js.nodes.function.FunctionRootNode.executeInRealm(FunctionRootNode.java:139)
at com.oracle.truffle.js.runtime.JavaScriptRealmBoundaryRootNode.execute(JavaScriptRealmBoundaryRootNode.java:92)
at jdk.internal.vm.compiler/org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callProxy(OptimizedCallTarget.java:289)
at jdk.internal.vm.compiler/org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callRoot(OptimizedCallTarget.java:278)
at jdk.internal.vm.compiler/org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callBoundary(OptimizedCallTarget.java:265)
at jdk.internal.vm.compiler/org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.doInvoke(OptimizedCallTarget.java:247)
at jdk.internal.vm.compiler/org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callDirect(OptimizedCallTarget.java:230)
at jdk.internal.vm.compiler/org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode.callProxy(OptimizedDirectCallNode.java:88)
at jdk.internal.vm.compiler/org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode.call(OptimizedDirectCallNode.java:72)
at com.oracle.truffle.js.nodes.function.JSFunctionCallNode$DispatchedCallNode.executeCall(JSFunctionCallNode.java:1210)
at com.oracle.truffle.js.nodes.function.JSFunctionCallNode$CacheNode.executeCall(JSFunctionCallNode.java:879)
at com.oracle.truffle.js.nodes.function.JSFunctionCallNode$UninitializedCacheNode.executeCall(JSFunctionCallNode.java:913)
at com.oracle.truffle.js.nodes.function.JSFunctionCallNode.executeCall(JSFunctionCallNode.java:246)
at com.oracle.truffle.js.nodes.function.JSFunctionCallNode$CallNode.execute(JSFunctionCallNode.java:313)
at com.oracle.truffle.js.nodes.access.JSWriteCurrentFrameSlotNodeGen.execute_generic3(JSWriteCurrentFrameSlotNodeGen.java:149)
at com.oracle.truffle.js.nodes.access.JSWriteCurrentFrameSlotNodeGen.execute(JSWriteCurrentFrameSlotNodeGen.java:84)
at com.oracle.truffle.js.nodes.access.JSWriteCurrentFrameSlotNodeGen.executeVoid(JSWriteCurrentFrameSlotNodeGen.java:281)
at com.oracle.truffle.js.nodes.binary.DualNode.execute(DualNode.java:105)
at com.oracle.truffle.js.nodes.function.FunctionBodyNode.execute(FunctionBodyNode.java:66)
at com.oracle.truffle.js.nodes.function.FunctionRootNode.executeInRealm(FunctionRootNode.java:139)
at com.oracle.truffle.js.runtime.JavaScriptRealmBoundaryRootNode.execute(JavaScriptRealmBoundaryRootNode.java:92)
at jdk.internal.vm.compiler/org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callProxy(OptimizedCallTarget.java:289)
at jdk.internal.vm.compiler/org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callRoot(OptimizedCallTarget.java:278)
at jdk.internal.vm.compiler/org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callBoundary(OptimizedCallTarget.java:265)
at jdk.internal.vm.compiler/org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.doInvoke(OptimizedCallTarget.java:247)
at jdk.internal.vm.compiler/org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callDirect(OptimizedCallTarget.java:230)
at jdk.internal.vm.compiler/org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode.callProxy(OptimizedDirectCallNode.java:88)
at jdk.internal.vm.compiler/org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode.call(OptimizedDirectCallNode.java:72)
at com.oracle.truffle.js.parser.JavaScriptLanguage$1.execute(JavaScriptLanguage.java:209)
at jdk.internal.vm.compiler/org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callProxy(OptimizedCallTarget.java:289)
at jdk.internal.vm.compiler/org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callRoot(OptimizedCallTarget.java:278)
at jdk.internal.vm.compiler/org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callBoundary(OptimizedCallTarget.java:265)
at jdk.internal.vm.compiler/org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.doInvoke(OptimizedCallTarget.java:247)
at jdk.internal.vm.compiler/org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.call(OptimizedCallTarget.java:223)
at org.graalvm.truffle/com.oracle.truffle.polyglot.PolyglotContextImpl.eval(PolyglotContextImpl.java:714)
at org.graalvm.sdk/org.graalvm.polyglot.Context.eval(Context.java:331)
at io.reactiverse.es4x.impl.graal.GraalRuntime.<init>(GraalRuntime.java:197)
at io.reactiverse.es4x.impl.graal.GraalRuntime.<init>(GraalRuntime.java:71)
at io.reactiverse.es4x.Runtime.getCurrent(Runtime.java:58)
at io.reactiverse.es4x.VerticleFactory.createVerticle(VerticleFactory.java:43)
at io.vertx.core.impl.DeploymentManager.createVerticles(DeploymentManager.java:237)
at io.vertx.core.impl.DeploymentManager.lambda$doDeployVerticle$2(DeploymentManager.java:210)
at io.vertx.core.impl.FutureImpl.setHandler(FutureImpl.java:79)
at io.vertx.core.impl.DeploymentManager.doDeployVerticle(DeploymentManager.java:177)
at io.vertx.core.impl.DeploymentManager.doDeployVerticle(DeploymentManager.java:149)
at io.vertx.core.impl.DeploymentManager.deployVerticle(DeploymentManager.java:137)
at io.vertx.core.impl.VertxImpl.deployVerticle(VertxImpl.java:665)
at io.vertx.core.impl.launcher.commands.VertxIsolatedDeployer.deploy(VertxIsolatedDeployer.java:42)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at io.vertx.core.impl.launcher.commands.ClasspathHandler.deploy(ClasspathHandler.java:159)
at io.vertx.core.impl.launcher.commands.RunCommand.deploy(RunCommand.java:397)
at io.vertx.core.impl.launcher.commands.RunCommand.run(RunCommand.java:270)
at io.vertx.core.impl.launcher.VertxCommandLauncher.execute(VertxCommandLauncher.java:226)
at io.vertx.core.impl.launcher.VertxCommandLauncher.dispatch(VertxCommandLauncher.java:380)
at io.vertx.core.impl.launcher.VertxCommandLauncher.dispatch(VertxCommandLauncher.java:324)
at io.vertx.core.Launcher.main(Launcher.java:45)
FYI: JVMC1=1 npm start
works
Allow chaining a JS promise with a Vert.x Future so the experience of working with both runtimes is smooth.
Currently the code generator uses MVEL templates which are to be deprecated in future Vert.x releases.
The templates need to be moved to an external artifact and converted to something else as MVEL is to be deprecated upstream
Currently the source code contains both Java8 and Java9 code which will render IDEs such as Idea useless. The project should split the java8/9 code to different sources to make it easier to work with an IDE.
Workers allow running blocking code on a thread, this is a feature available in modern browsers and on V8, with vert.x we don't need to bootstrap threads but rely on worker verticles, however there are a couple of issues here:
Worker
interface defines a blocking APIworkers
can only interact over messagesAlternative instead of having a constructor, we could have a factory:
VertxWorker
.create('filename.js', worker => {
// worker is now ready
worker.onmessage = msg => {
// handles messages received from the worker
}
worker.onerror = err => {
// handles errors from the worker
}
worker.postMessage([2, 3]);
...
worker.terminate();
});
This can be fixed with a JUL formatter and a use the ScriptException
class helpers
Currently the generated pom uses maven shade plugin and maven exec plugin. It can be simplified to use the maven-vertx-plugin
.
Hi,
i try to do that (proxy a request) :
vertx.createHttpServer().requestHandler((req) =>{
var client = vertx.createHttpClient(new HttpClientOptions());
var c_req = client.request(...)
c_req.headers().setAll(req.headers());
....
})
but i get this error :
(io.vertx.core.http.impl.headers.VertxHttpHeaders)] failed due to: java.lang.IllegalArgumentException: Multiple applicable overloads found for method name setAll (candidates: [Method[public io.vertx.core.MultiMap io.vertx.core.http.impl.headers.VertxHttpHeaders.setAll(io.vertx.core.MultiMap)], Method[public io.netty.handler.codec.http.HttpHeaders io.netty.handler.codec.http.HttpHeaders.setAll(io.netty.handler.codec.http.HttpHeaders)]], arguments: [JavaObject[...(io.vertx.core.http.impl.headers.VertxHttpHeaders)] (HostObject)])
can you help me ?
With Java11
Nashorn
has become deprecated. Users should migrate either to GraalVM
for Java8 like runtime or use >= JDK11 as the graal bits can be used with a stock JVM.
Allow AMD modules as an alternative to commonjs, this would allow to use es4x without a package manager for example.
Some NPM modules have very strong dependencies to node modules. While ES4X runs on graal it doesn't run on graal-node
as it uses vert.x event loop instead.
Module aliases would be aliased during the require
execution and would allow substitutions of given modules, for example: uuid -> es4x-uuid
.
Substitutions should be declared in the dependencies so it is not the job of this action to perform npm
lookups and version matching.
As the tile said, es4x seems not to be work with the *.ts
entry-point file.
I inited the project as the installing guide ,just changing the index.js
with index.ts
.
the content of index.ts file
(located at the root dir of project) as follows:
/// <reference types="@vertx/core/runtime" />
// @ts-check
import { Router } from '@vertx/web';
const app = Router.router(vertx);
app.route('/').handler(function (ctx) {
ctx.response().end('Hello from Vert.x Web!');
});
vertx.createHttpServer()
.requestHandler(app)
.listen(8080);
after typing in npm start
,the error log is as follows
> [email protected] start /Users/liuchangxing/vertxTest/social-vx-server
> es4x-launcher
ES4X is using graaljs in interpreted mode! Add the JVMCI compiler module in order to run in optimal mode!
ModuleError: Module "./index.ts" was not found
at <js> runMain(file:/Users/liuchangxing/vertxTest/social-vx-server/node_modules/.lib/es4x-0.8.0.jar!/io/reactiverse/es4x/jvm-npm.js:108:3597-3677)
at org.graalvm.polyglot.Value.execute(Value.java:338)
at io.reactiverse.es4x.impl.graal.GraalRuntime.invokeMethod(GraalRuntime.java:188)
at io.reactiverse.es4x.impl.graal.GraalRuntime.main(GraalRuntime.java:156)
at io.reactiverse.es4x.impl.graal.GraalRuntime.main(GraalRuntime.java:34)
at io.reactiverse.es4x.JSVerticleFactory$1.start(JSVerticleFactory.java:73)
at io.vertx.core.impl.DeploymentManager.lambda$doDeploy$8(DeploymentManager.java:552)
at io.vertx.core.impl.ContextImpl.executeTask(ContextImpl.java:320)
at io.vertx.core.impl.EventLoopContext.lambda$executeAsync$0(EventLoopContext.java:38)
at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:404)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:495)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:905)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.lang.Thread.run(Thread.java:748)
Failed in deploying verticle caused by ModuleError: Module "./index.ts" was not found
at <js> runMain(file:/Users/liuchangxing/vertxTest/social-vx-server/node_modules/.lib/es4x-0.8.0.jar!/io/reactiverse/es4x/jvm-npm.js:108:3597-3677)
at org.graalvm.polyglot.Value.execute(Value.java:338)
at io.reactiverse.es4x.impl.graal.GraalRuntime.invokeMethod(GraalRuntime.java:188)
at io.reactiverse.es4x.impl.graal.GraalRuntime.main(GraalRuntime.java:156)
at io.reactiverse.es4x.impl.graal.GraalRuntime.main(GraalRuntime.java:34)
at io.reactiverse.es4x.JSVerticleFactory$1.start(JSVerticleFactory.java:73)
at io.vertx.core.impl.DeploymentManager.lambda$doDeploy$8(DeploymentManager.java:552)
at io.vertx.core.impl.ContextImpl.executeTask(ContextImpl.java:320)
at io.vertx.core.impl.EventLoopContext.lambda$executeAsync$0(EventLoopContext.java:38)
at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:404)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:495)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:905)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.lang.Thread.run(Thread.java:748)
ModuleError: Module "./index.ts" was not found
at <js> runMain(file:/Users/liuchangxing/vertxTest/social-vx-server/node_modules/.lib/es4x-0.8.0.jar!/io/reactiverse/es4x/jvm-npm.js:108:3597-3677)
at org.graalvm.polyglot.Value.execute(Value.java:338)
at io.reactiverse.es4x.impl.graal.GraalRuntime.invokeMethod(GraalRuntime.java:188)
at io.reactiverse.es4x.impl.graal.GraalRuntime.main(GraalRuntime.java:156)
at io.reactiverse.es4x.impl.graal.GraalRuntime.main(GraalRuntime.java:34)
at io.reactiverse.es4x.JSVerticleFactory$1.start(JSVerticleFactory.java:73)
at io.vertx.core.impl.DeploymentManager.lambda$doDeploy$8(DeploymentManager.java:552)
at io.vertx.core.impl.ContextImpl.executeTask(ContextImpl.java:320)
at io.vertx.core.impl.EventLoopContext.lambda$executeAsync$0(EventLoopContext.java:38)
at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:404)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:495)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:905)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.lang.Thread.run(Thread.java:748)
Having a temp engine to configure the eventbus codec will cause intermittent issues debugging using Chrome inspector.
Like the original issue that spawned the module aliases ticket I'm working on getting a graphql service working in javascript but also available as a verticle to the rest of our backend. I'm using Apollo Server and wrote most of an adapter like their express adapter but using es4x instead.
However there's one file(so far) that's imported directly by apollo-server-core(node-fetch) that was never compiled down to ES5 code. It still contains a class so nashorn is throwing a parse error.
I tried just compiling the file to get it to standard ES5 and then used the alias directive to point at that file but when es4x builds the project it's still importing the file from node_modules instead of my build directory. I looked at the code in es4x where the alias gets handled and can't see why it wouldn't get picked up. I have no idea how to set up a debugger to step into that import code though since es4x is entirely on the java classpath so I don't even know where I could even stick a breakpoint.
Have you noticed any issues with the alias? Or maybe I'm just defining it incorrectly? I don't see any parts of the stack trace that indicate it tries to load the aliased file at all.
Stack trace:
java.lang.RuntimeException: node_modules/node-fetch/lib/index.js:21:0 ES6 class declarations and expressions are not yet implemented
class Blob {
^
at jdk.scripting.nashorn/jdk.nashorn.internal.codegen.Lower.throwNotImplementedYet(Lower.java:875)
at jdk.scripting.nashorn/jdk.nashorn.internal.codegen.Lower.enterClassNode(Lower.java:706)
at jdk.scripting.nashorn/jdk.nashorn.internal.ir.ClassNode.accept(ClassNode.java:131)
at jdk.scripting.nashorn/jdk.nashorn.internal.ir.VarNode.accept(VarNode.java:197)
at jdk.scripting.nashorn/jdk.nashorn.internal.ir.Node.accept(Node.java:286)
at jdk.scripting.nashorn/jdk.nashorn.internal.ir.Block.accept(Block.java:235)
at jdk.scripting.nashorn/jdk.nashorn.internal.ir.LexicalContextNode$Acceptor.accept(LexicalContextNode.java:57)
at jdk.scripting.nashorn/jdk.nashorn.internal.ir.Block.accept(Block.java:511)
at jdk.scripting.nashorn/jdk.nashorn.internal.ir.FunctionNode.accept(FunctionNode.java:405)
at jdk.scripting.nashorn/jdk.nashorn.internal.ir.LexicalContextNode$Acceptor.accept(LexicalContextNode.java:57)
at jdk.scripting.nashorn/jdk.nashorn.internal.ir.LexicalContextExpression.accept(LexicalContextExpression.java:47)
at jdk.scripting.nashorn/jdk.nashorn.internal.ir.FunctionNode.accept(FunctionNode.java:57)
at jdk.scripting.nashorn/jdk.nashorn.internal.ir.ExpressionStatement.accept(ExpressionStatement.java:82)
at jdk.scripting.nashorn/jdk.nashorn.internal.ir.Node.accept(Node.java:286)
at jdk.scripting.nashorn/jdk.nashorn.internal.ir.Block.accept(Block.java:235)
at jdk.scripting.nashorn/jdk.nashorn.internal.ir.LexicalContextNode$Acceptor.accept(LexicalContextNode.java:57)
at jdk.scripting.nashorn/jdk.nashorn.internal.ir.Block.accept(Block.java:511)
at jdk.scripting.nashorn/jdk.nashorn.internal.ir.FunctionNode.accept(FunctionNode.java:405)
at jdk.scripting.nashorn/jdk.nashorn.internal.ir.LexicalContextNode$Acceptor.accept(LexicalContextNode.java:57)
at jdk.scripting.nashorn/jdk.nashorn.internal.ir.LexicalContextExpression.accept(LexicalContextExpression.java:47)
at jdk.scripting.nashorn/jdk.nashorn.internal.ir.FunctionNode.accept(FunctionNode.java:57)
at jdk.scripting.nashorn/jdk.nashorn.internal.codegen.CompilationPhase.transformFunction(CompilationPhase.java:635)
at jdk.scripting.nashorn/jdk.nashorn.internal.codegen.CompilationPhase$LoweringPhase.transform(CompilationPhase.java:78)
at jdk.scripting.nashorn/jdk.nashorn.internal.codegen.CompilationPhase.apply(CompilationPhase.java:631)
at jdk.scripting.nashorn/jdk.nashorn.internal.codegen.Compiler.compile(Compiler.java:657)
at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.Context.compile(Context.java:1546)
at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.Context.compileScript(Context.java:1467)
at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.Context.evaluateSource(Context.java:1433)
at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.Context.load(Context.java:962)
at jdk.scripting.nashorn/jdk.nashorn.internal.objects.Global.load(Global.java:1720)
at jdk.scripting.nashorn.scripts/jdk.nashorn.internal.scripts.Script$Recompilation$113$1552AAAAA$jvm_npm.L:17#_load(jar:file:/Users/jerry/.m2/repository/io/reactiverse/es4x/0.7.3/es4x-0.7.3.jar!/io/reactiverse/es4x/jvm-npm.js:92)
at jdk.scripting.nashorn.scripts/jdk.nashorn.internal.scripts.Script$Recompilation$169$4366AA$jvm_npm.L:17#Require(jar:file:/Users/jerry/.m2/repository/io/reactiverse/es4x/0.7.3/es4x-0.7.3.jar!/io/reactiverse/es4x/jvm-npm.js:143)
at jdk.scripting.nashorn.scripts/jdk.nashorn.internal.scripts.Script$Recompilation$137$1464A$jvm_npm.L:17#Module#require(jar:file:/Users/jerry/.m2/repository/io/reactiverse/es4x/0.7.3/es4x-0.7.3.jar!/io/reactiverse/es4x/jvm-npm.js:46)
at jdk.scripting.nashorn.scripts/jdk.nashorn.internal.scripts.Script$Recompilation$404$1AAAAA$fetch/0x00000008004d0040.L:1(node_modules/apollo-server-env/dist/polyfills/fetch.js:3)
at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:665)
at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:513)
at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:527)
at jdk.scripting.nashorn/jdk.nashorn.internal.objects.NativeFunction.apply(NativeFunction.java:104)
at jdk.scripting.nashorn.scripts/jdk.nashorn.internal.scripts.Script$Recompilation$113$1552AAAAA$jvm_npm.L:17#_load(jar:file:/Users/jerry/.m2/repository/io/reactiverse/es4x/0.7.3/es4x-0.7.3.jar!/io/reactiverse/es4x/jvm-npm.js:97)
at jdk.scripting.nashorn.scripts/jdk.nashorn.internal.scripts.Script$Recompilation$169$4366AA$jvm_npm.L:17#Require(jar:file:/Users/jerry/.m2/repository/io/reactiverse/es4x/0.7.3/es4x-0.7.3.jar!/io/reactiverse/es4x/jvm-npm.js:143)
at jdk.scripting.nashorn.scripts/jdk.nashorn.internal.scripts.Script$Recompilation$137$1464A$jvm_npm.L:17#Module#require(jar:file:/Users/jerry/.m2/repository/io/reactiverse/es4x/0.7.3/es4x-0.7.3.jar!/io/reactiverse/es4x/jvm-npm.js:46)
at jdk.scripting.nashorn.scripts/jdk.nashorn.internal.scripts.Script$Recompilation$132$1AAAAA$index$cu1$restOf/0x0000000800414c40.L:1(node_modules/apollo-server-env/dist/index.js:9)
at jdk.scripting.nashorn.scripts/jdk.nashorn.internal.scripts.Script$Recompilation$113$1552AAAAA$jvm_npm.L:17#_load(jar:file:/Users/jerry/.m2/repository/io/reactiverse/es4x/0.7.3/es4x-0.7.3.jar!/io/reactiverse/es4x/jvm-npm.js:97)
at jdk.scripting.nashorn.scripts/jdk.nashorn.internal.scripts.Script$Recompilation$106$4366AA$jvm_npm.L:17#Require(jar:file:/Users/jerry/.m2/repository/io/reactiverse/es4x/0.7.3/es4x-0.7.3.jar!/io/reactiverse/es4x/jvm-npm.js:143)
at jdk.scripting.nashorn.scripts/jdk.nashorn.internal.scripts.Script$Recompilation$88$1464A$jvm_npm.L:17#Module#require(jar:file:/Users/jerry/.m2/repository/io/reactiverse/es4x/0.7.3/es4x-0.7.3.jar!/io/reactiverse/es4x/jvm-npm.js:46)
at jdk.scripting.nashorn.scripts/jdk.nashorn.internal.scripts.Script$Recompilation$128$1AAAAA$index$cu1$restOf.L:1(node_modules/apollo-server-core/dist/index.js:9)
at jdk.scripting.nashorn.scripts/jdk.nashorn.internal.scripts.Script$Recompilation$113$1552AAAAA$jvm_npm.L:17#_load(jar:file:/Users/jerry/.m2/repository/io/reactiverse/es4x/0.7.3/es4x-0.7.3.jar!/io/reactiverse/es4x/jvm-npm.js:97)
at jdk.scripting.nashorn.scripts/jdk.nashorn.internal.scripts.Script$Recompilation$106$4366AA$jvm_npm.L:17#Require(jar:file:/Users/jerry/.m2/repository/io/reactiverse/es4x/0.7.3/es4x-0.7.3.jar!/io/reactiverse/es4x/jvm-npm.js:143)
at jdk.scripting.nashorn.scripts/jdk.nashorn.internal.scripts.Script$Recompilation$88$1464A$jvm_npm.L:17#Module#require(jar:file:/Users/jerry/.m2/repository/io/reactiverse/es4x/0.7.3/es4x-0.7.3.jar!/io/reactiverse/es4x/jvm-npm.js:46)
at jdk.scripting.nashorn.scripts/jdk.nashorn.internal.scripts.Script$Recompilation$115$1AAAAA$index$cu1$restOf.L:1(build/src/apollo-server-es4x/index.js:6)
at jdk.scripting.nashorn.scripts/jdk.nashorn.internal.scripts.Script$Recompilation$113$1552AAAAA$jvm_npm$cu1$restOf.L:17#_load(jar:file:/Users/jerry/.m2/repository/io/reactiverse/es4x/0.7.3/es4x-0.7.3.jar!/io/reactiverse/es4x/jvm-npm.js:97)
at jdk.scripting.nashorn.scripts/jdk.nashorn.internal.scripts.Script$Recompilation$106$4366AA$jvm_npm$cu1$restOf.L:17#Require(jar:file:/Users/jerry/.m2/repository/io/reactiverse/es4x/0.7.3/es4x-0.7.3.jar!/io/reactiverse/es4x/jvm-npm.js:143)
at jdk.scripting.nashorn.scripts/jdk.nashorn.internal.scripts.Script$Recompilation$88$1464A$jvm_npm.L:17#Module#require(jar:file:/Users/jerry/.m2/repository/io/reactiverse/es4x/0.7.3/es4x-0.7.3.jar!/io/reactiverse/es4x/jvm-npm.js:46)
at jdk.scripting.nashorn.scripts/jdk.nashorn.internal.scripts.Script$Recompilation$97$dev.L:1(build/src/dev.js:3)
at jdk.scripting.nashorn.scripts/jdk.nashorn.internal.scripts.Script$Recompilation$95$1552AAZAA$jvm_npm$cu1$restOf.L:17#_load(jar:file:/Users/jerry/.m2/repository/io/reactiverse/es4x/0.7.3/es4x-0.7.3.jar!/io/reactiverse/es4x/jvm-npm.js:97)
at jdk.scripting.nashorn.scripts/jdk.nashorn.internal.scripts.Script$Recompilation$79$3510A$jvm_npm$cu1$restOf.L:17#runMain(jar:file:/Users/jerry/.m2/repository/io/reactiverse/es4x/0.7.3/es4x-0.7.3.jar!/io/reactiverse/es4x/jvm-npm.js:110)
at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:657)
at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:513)
at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:527)
at jdk.scripting.nashorn/jdk.nashorn.api.scripting.ScriptObjectMirror.call(ScriptObjectMirror.java:120)
at io.reactiverse.es4x.impl.nashorn.NashornRuntime.invokeMethod(NashornRuntime.java:116)
at io.reactiverse.es4x.impl.nashorn.NashornRuntime.main(NashornRuntime.java:89)
at io.reactiverse.es4x.JSVerticleFactory$1.start(JSVerticleFactory.java:79)
at io.vertx.core.impl.DeploymentManager.lambda$doDeploy$8(DeploymentManager.java:552)
at io.vertx.core.impl.ContextImpl.executeTask(ContextImpl.java:320)
at io.vertx.core.impl.EventLoopContext.lambda$executeAsync$0(EventLoopContext.java:38)
at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:404)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:462)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:897)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.base/java.lang.Thread.run(Thread.java:834)
Alias directive:
"es4xAlias": {
"node-fetch/lib/index.js": "./build/src/node-fetch-es5/index.js"
}
Using maven wrapper makes the build more reproducible since it does not rely on the locally installed maven version. Reduces the non-java developer deps as well.
See: http://www.graalvm.org/sdk/javadoc/org/graalvm/polyglot/io/FileSystem.html
scripts are loaded following vertx rules, but the underlying engine could use a different set of rules making things not obvious.
Currently the verticle factory will handle the starting script as a commonjs module, this is ok most of the time but can introduce small issues for bundled code e.g.:
The reason is that commonjs wraps the code into a IIFE
and the source maps will not match the reported location. For this a custom factory should be made available that would deploy a bundle with all the remaining polyfills except the commonjs
require.
I've set a TS file as my main file in the package.json, but wen running npm start
it throws the following error:
ModuleError: Module "./src/app.ts" was not found
I've managed to get the Java imports working great, but now I'm trying to import a class and it won't work. It appears it needs to be transpiled.
What doesn't work:
In my index.js I have import {Licensee} from './src/routes/licensee';
and licensee.js is just:
export class Licensee {
test() {
return 'IT WORKS';
}
}
What does work:
index.js:
const Licensee = require('./src/routes/licensee');
licensee.js:
exports.test = function() {
return 'IT WORKS';
};
Any tips on how to get it to transpile with the class? Very much appreciated! :)
Look into support this
Hello again; sorry, this isn't quite an issue, but wanted to see your thoughts on this.
I'm working on booting our apollo GraphQL app on es4x to see how it performs. I'm writing a vertx -> apollo adapter (similar to their express adapters/etc) for mounting apollo's core GQL logic as a vertx-web handler and then will also write an "JS http call -> vertx http client" adapter for our outgoing microservices (we currently have them all go through request-promise
, but it should be pretty easy to write something that looks like request-promise
but uses the vertx client impl).
So, I think I've got the major inputs/outputs covered, but before getting that far, I'm also running into native node modules that our npm dependencies pull in; we generally don't use any custom-compiled/native node C API modules (AFAIU), but we do using some of these:
https://github.com/graalvm/graaljs/tree/master/graal-nodejs/doc/api
Particularly crypto
is what I'm running into now, because the JS uuid
npm package pulls it in to do UUID generation.
Some of the npm packages have browser fallbacks, e.g.:
https://github.com/kelektiv/node-uuid/blob/master/package.json#L35
So I'm curious:
a) do you think es4x can/should use the browser
fallback if its needed/available, and
b) do you think es4x will end up exposing/pulling in some of the graaljs-provided node modules (such as crypto
), or does that bring a bunch of other node dependencies/complexity (or worse runtime overhead?) that you don't want/need?
Thanks; understood you're in very early stages, so I'm probably getting ahead of things by trying to boot up a full-fledged/existing application, so these sort of issues might be premature.
Currently importing java types requires the user to call graal/nashorn specific code:
Java.type('fqcn');
Perhaps this could be hidden with a extension to the require function (modelled after the requirejs extensions).
const System = require('!java.lang.System');
System.out.println("Hello!");
The !
marks a plugin if there's anything before it's the kind of plugin and what comes after is the argument to the plugin.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.