ECMA 2021+ cache - TypeError: undefined has no such function "get"

  • Platform information:
    • Hardware: x86_64
    • OS: Ubuntu Linux 20.04.4
    • Java Runtime Environment: Azul Zulu 11.62+17 (11.0.18-b10)
    • openHAB version: openHAB 3.4.2 Release Build

When trying to use the example code from JavaScript Scripting - Automation | openHAB it does not run the script.
It complains about no such function.


var counter = cache.private.get('counter');
if (counter === null) {
  counter = { times: 0 };
  cache.private.put('counter', counter);
console.log('Count', counter.times++);

Console output:

13:20:41.861 [ERROR] [.internal.handler.ScriptActionHandler] - Script execution of rule with 
UID 'a4a6e27576' failed: org.graalvm.polyglot.PolyglotException: TypeError: 
undefined has no such function "get"

Installed JS Scripting is installed and selecting ECMA 2021+ when making the script:

What am i doing wrong?

Have you ever installed the openhab-js library manually? If so you are running with an old version that doesn’t support the cache. Uninstall it using npm remove.

You where right. I tried for for time back to install openhab-js manually.

But I never used npm so I cleaned up the openhab-conf\automation\js\node_modules and now it works.