Hi,
this week I started playing around with the powerful JSscripting 3.2 engine, but ran into a few issues using npm modules.
I tried using a script that runs fine with nodejs and makes use of libraries like Jimp, gifwrap and ws (WebSockets).
However, after installing the libraries in the node_modules directory, I soon ran into two types of problems:
- GraalVM seems to love all js files below this directory - including those integrated into the libraries for testing purposes etc.
[ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/etc/openhab/automation/js/node_modules/process/test.js': org.graalvm.polyglot.PolyglotException: TypeError: Cannot load CommonJS module: 'assert'
[ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/etc/openhab/automation/js/node_modules/xml2js/lib/builder.js': org.graalvm.polyglot.PolyglotException: TypeError: Cannot load CommonJS module: './defaults'
[ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/etc/openhab/automation/js/node_modules/xtend/test.js': org.graalvm.polyglot.PolyglotException: TypeError: Cannot load CommonJS module: 'tape'
=> Do I understand correctly that this behavior is part of [jsscripting] JS script engine no longer watches node_modules for scripts by jpg0 · Pull Request #11830 · openhab/openhab-addons · GitHub and should be fixed when I install a nightly build?
- GraalVM does not provide all built-in functionality that is included with nodejs.
[ERROR] [b.automation.script.javascript.stack] - Failed to execute script: org.graalvm.polyglot.PolyglotException: TypeError: Cannot load CommonJS module: 'assert'
[ERROR] [b.automation.script.javascript.stack] - Failed to execute script: org.graalvm.polyglot.PolyglotException: TypeError: (intermediate value).nextTick is not a function
[ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'ede0555c07' failed: org.graalvm.polyglot.PolyglotException: TypeError: Cannot load CommonJS module: 'events'
[ERROR] [b.automation.script.javascript.stack] - Failed to execute script:
org.graalvm.polyglot.PolyglotException: TypeError: Cannot load CommonJS module: 'https'
Is there anything I can do to get this functionality?
Not tested yet, but I for sure know that some of the libs I use make extended use of Promises. Will these work, or will this become the next issue, given that GraalVM is single-threaded?
@rlkoshak Thanks for your great work and tutorials!