How can I get my ECMA scripts working on openHABian?

@rlkoshak I’m the author of that fmi.js, and it Works For Me ™,
see Control a water heater and ground source heat pump based on cheap hours of spot priced electricity - #13 by masipila

I’m running openHAB 3.3.0 on openHabian, also on Raspberry Pi 4 like @ruxu

I was first suspecting that the path in the require statement would be incorrect, so I modified my script action so that the path was incorrect. That results in a different error message in the logs, that would be
org.graalvm.polyglot.PolyglotException: TypeError: Cannot load CommonJS module: 'invalid-path-here/fmi.js'

So that suggests (does not prove, but suggests) that @ruxu’s script action is able to read the fmi.js from /etc/openhab/automation/js/node_modules/kotikolo/fmi.js

@ruxu Let’s try a simple hello world script.

Create a file hello-world.js so that the full path will be
/etc/openhab/automation/js/node_modules/kotikolo/hello-world.js

The hello-world.js will be as follows:

module.exports = {
    hello: hello,
};

function hello() {
    console.log('Hello World!');
}

The script action that will call this js file will be:

hw = require('kotikolo/hello-world.js');
hw.hello();

Executing this script action should result in the following log entry that looks like this:
2022-09-13 21:15:15.258 [INFO ] [g.openhab.automation.script.ui.hello] - Hello World!

Cheers,
Markus