Which ECMAScript engine? There is the default ECMAScript 5.1 which comes with openHAB and there is the GraalVM JavaScript add-on you can install separately. The two are not the same and rules written in one are not compatible with the other. When you do install the GraalVM add-on, for some reason it breaks the built in JavaScript right now (I’ve opened an issue but it’s not gained traction yet) so if you do install the add-on, you must only use that for your rules.
It’s clear from the error that it’s coming from GraalVM JavaScript.