Function node displays `The workspace contains some nodes that are not properly configured:`

I'm using some javascript in a function node, but when I deploy it, I get a red triangle on the node, and a pop-up saying The workspace contains some nodes that are not properly configured: and options is highlighted from this line;
const parts = new Intl.DateTimeFormat('en-GB', options).formatToParts(now);
The javascript runs ok, and does what it's supposed to do, but it's a pain having to acknowledge the popup every time I deploy.
Is there a problem with the code?

// Get or initialize chart data
let chartData1 = flow.get("chartData1") || {
    x: [],
    y: []
};

// Handle flush request
if (msg.topic === "flush") {
    msg.payload = [{
        x: chartData1.x,
        y: chartData1.y,
        type: "line"
    }];
    return msg;
}

// Validate input
if (!msg.payload || typeof msg.payload.grid !== "number") {
    return null;  // drop if invalid
}

// Normal update: append new point
const now = new Date();
const options = {
    timeZone: 'Europe/London',
    year: 'numeric',
    month: '2-digit',
    day: '2-digit',
    hour: '2-digit',
    minute: '2-digit',
    second: '2-digit',
    hourCycle: 'h23' // use 24-hour format
};
const parts = new Intl.DateTimeFormat('en-GB', options).formatToParts(now);
const obj = Object.fromEntries(parts.map(p => [p.type, p.value]));
const time = `${obj.year}-${obj.month}-${obj.day} ${obj.hour}:${obj.minute}:${obj.second}`;

const value = msg.payload.grid;

chartData1.x.push(time);
chartData1.y.push(value);

// Limit size to 30 minutes
if (chartData1.x.length > 360) {
    chartData1.x.shift();
    chartData1.y.shift();
}
node.status("No of data points = " + chartData1.x.length);

// Save updated context
flow.set("chartData1", chartData1);

// Return just the latest point
msg.payload = [{
    x: [time],
    y: [value],
    type: "line"
}];

return msg;

Code looks fine and if I place in a function node I get no Red triangle.

Is there something in the set up tab?
Have you tried deleting the node and adding a new function node?

No

Yes, same result.

I’ve also tried changing the name of the constant ‘options’, and also moving the declaration to the top of the code.

Node-RED version: v4.1.0
Node.js version: v20.19.4
Linux 6.8.0-1030-oracle arm64 LE (Ubuntu)
Oracle cloud server

I am wondering if the .formatToParts(now) is the issue. Have you tried now() or Date.now()

1 Like

I am seeing the same thing. If you put the options inline in the call it is ok.

const parts = new Intl.DateTimeFormat('en-GB', {
    timeZone: 'Europe/London',
    year: 'numeric',
    month: '2-digit',
    day: '2-digit',
    hour: '2-digit',
    minute: '2-digit',
    second: '2-digit',
    hourCycle: 'h23' // use 24-hour format
}).formatToParts(now);

I think it must be a bug in the syntax checker code. Hovering over options (in the original) which has a red line under it says that there is no matching overload, but the popup is not large enough to see exactly what it is complaining about, and I can't work out how to see all of the message.

1 Like

I had that, you can also get rid of the error by having /** @type {Intl.DateTimeFormatOptions} */ just before the const options = { line

1 Like

This is why: Monaco clarification - #32 by Steve-Mcl

1 Like

I'd forgotten that whole conversation, on exactly the same problem :grin:

Adding /** @type {Intl.DateTimeFormatOptions} */ certainly clears the problems, but the strange thing is that I started using that code over 4 weeks ago with no issues whatsoever, and it only started showing yesterday after I re-opened the function node just to look at something. I made no changes, but when I clicked ‘Done’ to exit the node, the issue started.
(I’ll be glad when the ‘click outside the box’ issue is rolled back :wink: )

But all good now, thanks for all of the responses.