Custom installation of openhab-js - problems

As stated in the documentation the custom installation of openhab-js (https://openhab.github.io/openhab-js/) on to of the already installed default installation (by JS automation binding) shall be done by running

npm -i openhab

in the config/automation/js directory.

After executing the npm command I get a bunch of log entries like this:

2022-01-08 14:22:31.539 [INFO ] [rulesupport.loader.ScriptFileWatcher] - Loading script '/openhab/conf/automation/js/node_modules/openhab/actions.js'
2022-01-08 14:22:32.205 [ERROR] [b.automation.script.javascript.stack] - Failed to execute script:
org.graalvm.polyglot.PolyglotException: TypeError: Cannot load CommonJS module: './osgi'
	at com.oracle.truffle.polyglot.PolyglotMapAndFunction.apply(PolyglotMapAndFunction.java:46) ~[?:?]
	at org.openhab.automation.jsscripting.internal.OpenhabGraalJSScriptEngine.lambda$7(OpenhabGraalJSScriptEngine.java:200) ~[?:?]
	at java.util.Optional.orElseGet(Optional.java:369) ~[?:?]
	at org.openhab.automation.jsscripting.internal.OpenhabGraalJSScriptEngine.lambda$5(OpenhabGraalJSScriptEngine.java:200) ~[?:?]
	at <js>.:program(actions.js:19) ~[?:?]
	at org.graalvm.polyglot.Context.eval(Context.java:379) ~[?:?]
	at com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.eval(GraalJSScriptEngine.java:458) ~[?:?]
	at com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.eval(GraalJSScriptEngine.java:400) ~[?:?]
	at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:249) ~[java.scripting:?]
	at org.openhab.automation.jsscripting.internal.scriptengine.DelegatingScriptEngineWithInvocable.eval(DelegatingScriptEngineWithInvocable.java:56) ~[?:?]
	at org.openhab.automation.jsscripting.internal.scriptengine.InvocationInterceptingScriptEngineWithInvocable.eval(InvocationInterceptingScriptEngineWithInvocable.java:79) ~[?:?]
	at org.openhab.automation.jsscripting.internal.scriptengine.DelegatingScriptEngineWithInvocable.eval(DelegatingScriptEngineWithInvocable.java:56) ~[?:?]
	at org.openhab.automation.jsscripting.internal.scriptengine.InvocationInterceptingScriptEngineWithInvocable.eval(InvocationInterceptingScriptEngineWithInvocable.java:79) ~[?:?]
	at org.openhab.core.automation.module.script.internal.ScriptEngineManagerImpl.loadScript(ScriptEngineManagerImpl.java:177) ~[?:?]
	at org.openhab.core.automation.module.script.rulesupport.loader.ScriptFileWatcher.createAndLoad(ScriptFileWatcher.java:231) ~[?:?]
	at org.openhab.automation.jsscripting.internal.fs.watch.JSScriptFileWatcher.createAndLoad(JSScriptFileWatcher.java:57) ~[?:?]
	at org.openhab.core.automation.module.script.rulesupport.loader.ScriptFileWatcher.importFile(ScriptFileWatcher.java:211) ~[?:?]
	at org.openhab.core.automation.module.script.rulesupport.loader.ScriptFileWatcher.lambda$2(ScriptFileWatcher.java:203) ~[?:?]
	at java.util.Optional.ifPresent(Optional.java:183) [?:?]
	at org.openhab.core.automation.module.script.rulesupport.loader.ScriptFileWatcher.importFileWhenReady(ScriptFileWatcher.java:201) [bundleFile:?]
	at org.openhab.core.automation.module.script.rulesupport.loader.ScriptFileWatcher.processWatchEvent(ScriptFileWatcher.java:178) [bundleFile:?]
	at org.openhab.core.service.WatchQueueReader.run(WatchQueueReader.java:240) [bundleFile:?]
	at java.lang.Thread.run(Thread.java:829) [?:?]
2022-01-08 14:22:32.216 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/openhab/conf/automation/js/node_modules/openhab/actions.js': org.graalvm.polyglot.PolyglotException: TypeError: Cannot load CommonJS module: './osgi'
2022-01-08 14:22:32.219 [INFO ] [rulesupport.loader.ScriptFileWatcher] - Loading script '/openhab/conf/automation/js/node_modules/openhab/cache.js'
2022-01-08 14:22:32.806 [INFO ] [rulesupport.loader.ScriptFileWatcher] - Loading script '/openhab/conf/automation/js/node_modules/openhab/index.js'
2022-01-08 14:22:33.797 [INFO ] [rulesupport.loader.ScriptFileWatcher] - Loading script '/openhab/conf/automation/js/node_modules/openhab/itemchannellink.js'
2022-01-08 14:22:39.431 [ERROR] [b.automation.script.javascript.stack] - Failed to execute script:
org.graalvm.polyglot.PolyglotException: TypeError: Cannot load CommonJS module: './log'
	at com.oracle.truffle.polyglot.PolyglotMapAndFunction.apply(PolyglotMapAndFunction.java:46) ~[?:?]
	at org.openhab.automation.jsscripting.internal.OpenhabGraalJSScriptEngine.lambda$7(OpenhabGraalJSScriptEngine.java:200) ~[?:?]
	at java.util.Optional.orElseGet(Optional.java:369) ~[?:?]
	at org.openhab.automation.jsscripting.internal.OpenhabGraalJSScriptEngine.lambda$5(OpenhabGraalJSScriptEngine.java:200) ~[?:?]
	at <js>.:program(itemchannellink.js:9) ~[?:?]
	at org.graalvm.polyglot.Context.eval(Context.java:379) ~[?:?]
	at com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.eval(GraalJSScriptEngine.java:458) ~[?:?]
	at com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.eval(GraalJSScriptEngine.java:400) ~[?:?]
	at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:249) ~[java.scripting:?]
	at org.openhab.automation.jsscripting.internal.scriptengine.DelegatingScriptEngineWithInvocable.eval(DelegatingScriptEngineWithInvocable.java:56) ~[?:?]
	at org.openhab.automation.jsscripting.internal.scriptengine.InvocationInterceptingScriptEngineWithInvocable.eval(InvocationInterceptingScriptEngineWithInvocable.java:79) ~[?:?]
	at org.openhab.automation.jsscripting.internal.scriptengine.DelegatingScriptEngineWithInvocable.eval(DelegatingScriptEngineWithInvocable.java:56) ~[?:?]
	at org.openhab.automation.jsscripting.internal.scriptengine.InvocationInterceptingScriptEngineWithInvocable.eval(InvocationInterceptingScriptEngineWithInvocable.java:79) ~[?:?]
	at org.openhab.core.automation.module.script.internal.ScriptEngineManagerImpl.loadScript(ScriptEngineManagerImpl.java:177) ~[?:?]
	at org.openhab.core.automation.module.script.rulesupport.loader.ScriptFileWatcher.createAndLoad(ScriptFileWatcher.java:231) ~[?:?]
	at org.openhab.automation.jsscripting.internal.fs.watch.JSScriptFileWatcher.createAndLoad(JSScriptFileWatcher.java:57) ~[?:?]
	at org.openhab.core.automation.module.script.rulesupport.loader.ScriptFileWatcher.importFile(ScriptFileWatcher.java:211) ~[?:?]
	at org.openhab.core.automation.module.script.rulesupport.loader.ScriptFileWatcher.lambda$2(ScriptFileWatcher.java:203) ~[?:?]
	at java.util.Optional.ifPresent(Optional.java:183) [?:?]
	at org.openhab.core.automation.module.script.rulesupport.loader.ScriptFileWatcher.importFileWhenReady(ScriptFileWatcher.java:201) [bundleFile:?]
	at org.openhab.core.automation.module.script.rulesupport.loader.ScriptFileWatcher.processWatchEvent(ScriptFileWatcher.java:178) [bundleFile:?]
	at org.openhab.core.service.WatchQueueReader.run(WatchQueueReader.java:240) [bundleFile:?]
	at java.lang.Thread.run(Thread.java:829) [?:?]
2022-01-08 14:22:39.444 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/openhab/conf/automation/js/node_modules/openhab/itemchannellink.js': org.graalvm.polyglot.PolyglotException: TypeError: Cannot load CommonJS module: './log'

I have to run

npm uninstall openhab

in order to get things working back to normal.

what am I doing wrong here?

It’s might be there ya a big in the latest version of openhab-js. I’ve installed the library using npm -i like you described before. I’m not sure how updates to npm are managed.

I am pretty sure it worked yesterday.

  • Today I created a new container from scratch.
  • I installed the JSScripting binding
  • Installed the openjab-js (npm i openhab)

and get the pile of error log entries.
Gonna open an issue on github

@florian-h05 It seems that these error messages can be ignored for the moment too?

Yes, it seems that they are also caused by the issue where GraalVM loads the content of node_modulesas scripts.

I would ignore them for the moment and wait for the fix here [jsscripting] JS script engine no longer watches node_modules for scripts by jpg0 · Pull Request #11830 · openhab/openhab-addons · GitHub.
When this PR has been merged and published in a release, we should check whether there error messages are gone.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.