I’m playing around to with jsscripting in 3.2 to replace my custom stuff from 3.1. It’s really cool to see the javascript development in 3.2. I’m a bit surprised that all files from the js\node_modules directories are loaded at startup. This leads to a lot of errors at startup. The files should be loaded only by a require(). As it looks they are the import statements of @js-joda.
Here is an example:
19:15:24.886 [INFO ] [.rulesupport.loader.ScriptFileWatcher] - Loading script '/C:/openhab/OPENHA~2.0/conf/automation/js/node_modules/@js-joda/core/src/format/DateTimeBuilder.js'
19:15:24.915 [ERROR] [ab.automation.script.javascript.stack] - Failed to execute script:
org.graalvm.polyglot.PolyglotException: SyntaxError: DateTimeBuilder.js:7:0 Expected an operand but found import import
import { requireNonNull } from '../assert';
^
DateTimeBuilder.js:7:32 Expected ; but found ../assert
import { requireNonNull } from '../assert';
For my test I installed the openhab module via npm install openhab and selected the option “Do Not Use Built-in Variables”.
I’ve worked an a solution for the node_modules directory issue. At the same time I’ve changed the behaviour to allow loading of relative files from the root folder.
You can download my build jar from github and create an .ohignore file in the automation/js directory
Use it like a .gitignore file and add following content as example.
node_modules/**
.git/**
do-not-load-me.js
This should skip all files within the node_modules directory and .git directory (if you use git). And the file do-not-load-me.js in the automation/js directory.