ioBroker.javascript icon indicating copy to clipboard operation
ioBroker.javascript copied to clipboard

[Bug]: moment-duration-format generates script error with js-controller 6.x

Open MK-66 opened this issue 8 months ago • 7 comments

I'm sure that

  • [X] This issue is still present in the current beta version of this adapter
  • [X] There is no other (open) issue with the same topic (use the search!)
  • [X] This issue is not described in the adapter documentation / FAQ (read the docs!)

Script type

JavaScript

The problem

With js-controller 6.x, a script with the npm module moment-duration-format generates following error: error: moment.duration(...).format is not a function.

The npm modules moment and moment-duration-format are installed in the javascript adapter and no errors are output when the adapter is started, only the script itself generates the error in the log. Moment and moment.duration do not generate any errors in the script, the error only occurs with moment.duration.format.

Sript line: let uptime = (existsState(id + '.uptime')) ? moment.duration(getState(id + '.uptime').val, 'seconds').format("D[T] H[h] m[m]", 0) : '-';

The same script works normally under js-controller 5.0.19 without any errors.

Screenshot npm-module javascript adapter:

Screenshot javascript moduls

iobroker.current.log (in debug mode!)

Full error log entry of the script: script.js.MD.MD_AdapterStatus_TEST: [adapterStatus] error:moment.duration(...).format is not a function, stack: TypeError: moment.duration(...).format is not a function at adapterStatus (script.js.MD.MD_AdapterStatus_TEST:248:115) at script.js.MD.MD_AdapterStatus_TEST:561:1 at script.js.MD.MD_AdapterStatus_TEST:711:3 at Script.runInContext (node:vm:148:12) at Script.runInNewContext (node:vm:153:17) at execute (/opt/iobroker/node_modules/iobroker.javascript/main.js:1968:23) at prepareScript (/opt/iobroker/node_modules/iobroker.javascript/main.js:2215:13) at /opt/iobroker/node_modules/iobroker.javascript/main.js:2307:17 at Immediate._onImmediate (/opt/iobroker/node_modules/iobroker.javascript/main.js:1722:17) at processImmediate (node:internal/timers:480:21)

Version of nodejs

20.14.0

Version of ioBroker js-controller

6.0.4

Version of adapter

8.6.0

MK-66 avatar Jun 15 '24 13:06 MK-66