Open MK-66 opened 3 months ago
Looks like moment has no default export
Suggestions @foxriver76 ?
https://www.npmjs.com/package/moment-duration-format#module This works correct, controller v6.0.5, js adapter 8.6.0
So maybe normally it had some side effects automatically which now need to be configured explicitly but for this we would need to see your code @MK-66
This also works
console.log(moment.duration(123, "minutes").format("h:mm"));
So maybe you just need momentDurationFormatSetup(moment);
after the imports.
@foxriver76, @klein0r
The line momentDurationFormatSetup(moment);
is obviously exactly the right one that was missing in the script.
Unfortunately I'm not a javascript pro, so thanks for the hint.
Issue can then be closed from my point of view, should I close the issue then?
If this happens to a lot of users we will think about adding a short news on how to fix it, please leave it open until we close it.
please leave it open
sorry 😄
Probably related: #1642
I'm sure that
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:
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