NodeRed not finding moment.js - "TypeError: moment is not a function"

I have installed moment through "manage pallete".
Also added to settings.js

 functionGlobalContext: {
   moment: require('moment')  
}

But when trygin to execute a function node:

const moment = global.get('moment');  
var tempon = global.get('ultimaON');
var tempoff = global.get('ultimaOFF');
const hoje = moment();
const dataOn = moment(tempon);
const dataOff = moment(tempoff);
const diferencaDiasON = hoje.diff(dataOn, 'days');
const diferencaDiasOFF = hoje.diff(dataOff, 'days');
if (!dataOn.isValid()) {
    node.warn("Data em 'tempon' não é válida.");
}

if (!dataOff.isValid()) {
    node.warn("Data em 'tempoff' não é válida.");
}

return [
    { payload: diferencaDiasON }, // Diferença de dias para tempon
    { payload: diferencaDiasOFF } // Diferença de dias para tempoff
];

I am getting "TypeError: moment is not a function"

I assume you mean you have installed a node-red contrib node that has the name moment in it? like node-red-contrib-moment ? That will not give you access to the moment library in a function node!

Why not simply add moment through the setup tab on the function? e.g:
Use any npm module in Node-RED • FlowFuse

Or, why not simply use the node-red-contrib-moment node to do this all graphically in the low-code environment?

Or, better still, use built in $moment JSONata function in a change node?

You assumed right.

I will try the moment contrib node. I am not experienced with json.

I used ChatGPT to generated the code I posted. Thanks a lot