Node-Red showing error in Function Node but it works correctly

I have this code in a function node. It shows an error but I checked in Notepad++ and not issues. It does deploy and seems to run correctly. Any ideas on what the error is?

// check payload
if (msg.payload === "") {
    // empty payload, imput came from inject node
    // check that we have someting in context store
    // if not, set default
    if ( typeof flow.get("timeframe") == 'undefined') {
        flow.set("timeframe", "1");
        flow.set("unit", "minute");
        flow.set("unitstepsize", 10);
        flow.set("querymean", "");
        flow.set("xaxis",60);
    }
} else {
    // non-empty payload, input from multistate button    
    switch (msg.payload) {
        case "1":
            unit = "minute";
            unitstepsize = 10;
            querymean = "";
            xaxis = 1;
            break;
        case "3":
            unit = "minute";
            unitstepsize = 15;
            querymean = '|> timedMovingAverage(every: 1m, period: 1m)';
            xaxis = 180;
            break;
        case "24":
            unit = "hour";
            unitstepsize = 3;
            querymean = '|> timedMovingAverage(every: 10m, period: 10m)';
            xaxis = 1440;
            break;
        case "168":
            unit = "day";
            unitstepsize = 1;
            querymean = '|> timedMovingAverage(every: 1h, period: 1h)';
            xaxis = 241920;
            break;
        default:
            // nothing in here, we don't expect something different from multistate switch!!!
            break;
    }
    flow.set("timeframe", msg.payload);
    flow.set("unit", unit);
    flow.set("unitstepsize", unitstepsize);
    flow.set("querymean", querymean);
    flow.set("xaxis",xaxis)
}

node.log("set fluxdata")
msg.fluxdata = {
    "bucket": "sensors",
    "measurement": "temperature"
};
//'from(bucket: "sensors") |> range(start: -1d) |> filter(fn: (r) => r._measurement == "temperature") ';


return msg;


Have you hovered you mouse over the red underlines?

The short answer is you have not declared the variables. A partial long answer - the editor highlights these things to help you avoid bugs.

Thanks, been too long since programming. I copied a solution that was missing the var statements, I mistakenly thought they had it correct.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.