ganaraj
ganaraj

Reputation: 420

vertx unable to deploy a node module

I am using vertx with npm and I want to include the googleapis into one of my verticles. To do so i installed googleapis using npm into the project. Node dependencies in package.json are mentioned below:

 {
   "name": "grey-bshlv",
   "dependencies": {
   "angular": "^1.5.7",
   "googleapis": "^10.0.0",
   "vertx3-full": "^3.3.0"
 },
 "scripts": {
 "start": "./node_modules/.bin/vertx run server.js"
 }

Contents of server.js

var Router = require("vertx-web-js/router");
var eb = vertx.eventBus();
var google = require("googleapis");
vertx.deployVerticle("verticles/static-data-verticle.js");

Now when i start vertx i keep getting the error "javax.script.ScriptException: Error: Cannot find module googleapis in at line number 141 at column number 6"

The complete error stack is provided below:

  javax.script.ScriptException: Error: Cannot find module googleapis in <eval> at line number 141 at column number 6
    at jdk.nashorn.api.scripting.NashornScriptEngine.throwAsScriptException(NashornScriptEngine.java:467)
    at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:451)
    at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:403)
    at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:399)
    at jdk.nashorn.api.scripting.NashornScriptEngine.eval(NashornScriptEngine.java:155)
    at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264)
    at io.vertx.lang.js.JSVerticleFactory$JSVerticle.start(JSVerticleFactory.java:109)
    at io.vertx.core.impl.DeploymentManager.lambda$doDeploy$8(DeploymentManager.java:434)
    at io.vertx.core.impl.ContextImpl.lambda$wrapTask$3(ContextImpl.java:359)
    at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:339)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:393)
    at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:742)
    at java.lang.Thread.run(Thread.java:745)
  Caused by: <eval>:141:6 Error: Cannot find module googleapis
    at jdk.nashorn.internal.objects.NativeError.initException(NativeError.java:137)
    at jdk.nashorn.internal.objects.NativeError.<init>(NativeError.java:102)
    at jdk.nashorn.internal.objects.NativeError.<init>(NativeError.java:106)
    at jdk.nashorn.internal.objects.NativeError.<init>(NativeError.java:110)
    at jdk.nashorn.internal.objects.NativeError.constructor(NativeError.java:129)
    at jdk.nashorn.internal.scripts.Script$Recompilation$4$4376AAAA$\^eval\_.L:33$doRequire(null:141)
    at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:631)
    at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:494)
    at jdk.nashorn.internal.runtime.ScriptFunction.invokeSync(ScriptFunction.java:1287)
    at jdk.nashorn.internal.scripts.Script$Recompilation$3$4049AAA$\^eval\_.L:33$Require(null:120)
    at jdk.nashorn.internal.scripts.Script$Recompilation$18$2109A$\^eval\_.L:33$Module$require(null:68)
    at jdk.nashorn.internal.scripts.Script$Recompilation$134$57AAAAA$\^eval\_#88\!17\^eval\_.L:1(server.js:3)
    at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:633)
    at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:494)
    at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:393)
    at jdk.nashorn.internal.scripts.Script$Recompilation$14$2235AAAAA$\^eval\_.L:33$_load(null:113)
    at jdk.nashorn.internal.scripts.Script$Recompilation$4$4376AAAA$\^eval\_.L:33$doRequire(null:154)
    at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:631)
    at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:494)
    at jdk.nashorn.internal.runtime.ScriptFunction.invokeSync(ScriptFunction.java:1287)
    at jdk.nashorn.internal.scripts.Script$Recompilation$132$4168AAZ$\^eval\_.L:33$RequireNoCache(null:124)
    at jdk.nashorn.internal.scripts.Script$131$\^eval\_.:program(<eval>:1)
    at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:623)
    at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:494)
    at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:393)
    at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:446)
    ... 11 more
  Failed in deploying verticle 

Upvotes: 0

Views: 437

Answers (1)

Paulo Lopes
Paulo Lopes

Reputation: 5801

Nashorn and inherently Vert.x is not Node so modules such as:

  • fs
  • path
  • net

Will not be available since they are node specific/native. If your dependencies require any of those modules it will not be possible to use them in nashorn and therefore vert.x.

There is a warning on the documentation about it:

http://vertx.io/docs/vertx-core/js/

Upvotes: 1

Related Questions