Need help with using a module like 'moment' which fails with my setup.
This is the code added to a function node:
const moment = require('moment');
const now = moment();
// Format the timestamp
msg.payload = now.format('YYYY-MM-DD HH:mm:ss');
It results with an error:
ReferenceError: ReferenceError: require is not defined (line 21, col 16)
see more details below
I found functionExternalModules
needs to be enabled in settings.js
, it needs to restart NR. All done, no change --> Error
I run 'moment' directly from CLI, all good.
No further ideas here! What could be the problem?
(Node : v20.18.1 / npm : 10.8.2)
ReferenceError: require is not defined
at Function node:b54bf4877315a563 [open3e/ecu LISTEN --> FLOW]:22:16
at Function node:b54bf4877315a563 [open3e/ecu LISTEN --> FLOW]:106:3
at Script.runInContext (node:vm:149:12)
at processMessage (/usr/lib/node_modules/node-red/node_modules/@node-red/nodes/core/function/10-function.js:419:33)
at FunctionNode._inputCallback (/usr/lib/node_modules/node-red/node_modules/@node-red/nodes/core/function/10-function.js:342:17)
at /usr/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/nodes/Node.js:214:26
at Object.trigger (/usr/lib/node_modules/node-red/node_modules/@node-red/util/lib/hooks.js:166:13)
at Node._emitInput (/usr/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/nodes/Node.js:206:11)
at Node.emit (/usr/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/nodes/Node.js:190:25)
at Node.receive (/usr/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/nodes/Node.js:499:10)
16 Jan 19:50:21 - [error] [function:open3e/ecu LISTEN --> FLOW] ReferenceError: ReferenceError: require is not defined (line 21, col 16)