I am trying to create a web application(in java) that can communicate with a ros server. Therefore I use the rosnode module. For the website I use vaadin. My problem is that I do not know how to call/execute the rosnode javascript based files.
When I try to call the rosnode.initNode I get the following error:
javax.script.ScriptException: SyntaxError: /home/philipp/webappvaadinros/my-starter-project/src/main/java/ros/webapp/com/nodejs/rosserver.js:3:0 Expected an operand but found let
let rosnodejs = require('/home/philipp/webappvaadinros/my-starter-project/node_modules/rosnodejs/dist/index.js');
^ in <eval> at line number 1
As scriptengine I use NashornScriptEngine. I should mention that I am new to javascript. Can anyone help me?
So it seems that you are using the Java Scripting API to call javascript and the statement that is tripping it up is the let
, which is a feature of the relatively recent ES6 standard. So I assume that scripting API simply doesn't support that yet. You can try to babel your code, just like rosnodejs does before publishing, or you can see whether you can change the node.js version used to evaluate scripts in that scripting API (if it even uses node.js -- sorry, not at all familiar with that API).
Frankly though, you might be better of using rosjava, instead of trying to jump between programming languages.