JSScripting in v3.2 loads node_modules on startup?

Hello,

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”.

Am I doing something wrong here?

So I’ve checked the option “Do Not Use Built-in Variables” and it makes no difference if used or not. It loads all file in nodes_modules.

Hello @jpg0 maybe you can identify this as bug or feature ? Or should I report it on GitHub?

@csowada that sounds like a bug - could you file one please?

1 Like

I’ve opened a PR to fix this: [jsscripting] JS script engine no longer watches subdirs for scripts by jpg0 · Pull Request #11830 · openhab/openhab-addons · GitHub

1 Like

Wow, you are really fast. Thank you very much.

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.