NPE Loading of third party libraries; JS Scripting

Hi, i want to use an external Node Libary (node-ical) in a script. My OpenHab (5.1.0) instance is running using official docker container. Following the documentation i installed npm in the container using nvm and installed the libary to /openhab/conf/automation/js & verified that the module was there under node_modules.

Next i tried to run a simple script using the libary:

// import ical
const ical = require('node-ical');

// or just parse some iCalendar data directly
const directEvents = ical.sync.parseICS(`
BEGIN:VCALENDAR
VERSION:2.0
CALSCALE:GREGORIAN
BEGIN:VEVENT
SUMMARY:Hey look! An example event!
DTSTART;TZID=America/New_York:20130802T103400
DTEND;TZID=America/New_York:20130802T110400
LOCATION:1000 Broadway Ave.\, Brooklyn
DESCRIPTION: Do something in NY.
STATUS:CONFIRMED
UID:7014-1567468800-1567555199@peterbraden@peterbraden.co.uk
END:VEVENT
END:VCALENDAR
`);
// log the ids of these events
console.log(Object.keys(directEvents));

Doing this, it seems there is an issue loading the node lib:

failed: java.lang.NullPointerException: Cannot invoke "java.nio.file.Path.resolve(String)" because the return value of "java.nio.file.Path.getRoot()" is null

I checked the file permissions in the container and all seems fine.
I could only reference this error to an old beta version using google; so any idea would be appreciated.

Thanks Chris

Is your rule code in the UI or a .js file?

If a file, is this the full contents of the .js file?

Do you have any other libraries installed which work or do all libraries give the same error. you can install openhab_rules_tools and require it just as a test if not. See openHAB Rules Tools Announcements for details on what this library does if you are curious. But installing it and importing it doesn’t really require extra details.

Hi, the problem occours either if it’s in UI Code (Rule, Script) or in a seprate file. But i could figure out the root cause … your hint with a different lib helped; even if i tried others before.

After spending some time setting up an development vm and debugging it seems all librariesi tested before had an dependecy to Node.js File System Module. This dependecy is the root cause for the exception. Also there seem to be no relation if it’s docker or “normal” local installation. I haven’t looked deeper into the code base that causes the NPE, might be possible to fix this or at least to improve the error message/exception.

My fix now: build my own “fork” of the ical parser without filesystem support.